﻿var $ = jQuery.noConflict();
var JustMarvel = JustMarvel || {};

(function ($) {
    // 封装
    JustMarvel.potting = {
        httpRequest: {
            // 针对搜索功能，
            // 一旦搜索后总是返回第一页，避免出现当前第5页，搜索后还处于第5页，
            // 但搜索结果不够5页而出现表格中没有数据的情况；
            // 简单的做法就是：如果href 中有page 参数则把其值改为1 即可，不管原值是否为 1。
            page: function (hrefString) {
                return hrefString.replace(/(page=\d+?)(&|$|#)/, function () {
                    return 'page=1' + arguments[2];
                });
            }
        },
        datetimepicker: {
            options: {
                language: 'zh-CN',
                format: 'yyyy-mm-dd',
                weekStart: 1,
                todayBtn: 1,
                autoclose: 1,
                todayHighlight: 1,
                startView: 2,
                minView: 2,
                forceParse: 0,
                fontAwesome: true,
                pickerPosition: "bottom-left"
            }
        },
        search: {
            searchInputEnterEvent: function () {
                // 取消所有搜索控件对回车键的默认监听行为（当form内只有一个input时，回车会进行刷新页面的操作；当同时存在另一个input时不会进行刷新--hidden 的input 除外。）；
                $('input#phname').on('keydown', function (e) {
                    if (e.keyCode == 13) {
                        // 可以不要取消冒泡的操作，保留着也可以~
                        e.stopPropagation();
                        return false; // 关键是这一行；
                    }
                });
            },
            // 对搜索功能的封装
            searchByKeyword: function () {
                this.searchInputEnterEvent();
                $('#searchname').on('click', function () {
                    var flag = true;
                    var href = window.location.href;
                    var phname = $('#phname').val();

                    if (phname == "") {
                        alert("请输入搜索条件");
                        return;
                    }

                    href = href.replace(/(phname=.*?)(&|$|#)/, function () {
                        flag = false;
                        return 'phname=' + phname + arguments[2];
                    });
                    if (flag) {
                        if (href.indexOf("?") > 0) {
                            href += '&phname=' + phname;
                        } else {
                            href += '?phname=' + phname;
                        }
                    }

                    // window.location.href = href;
                    window.location.href = JustMarvel.potting.httpRequest.page(href);
                });
            },
            searchByDateRange: function () {
                $('#startDate,#endDate').datetimepicker(JustMarvel.potting.datetimepicker.options);

                $('#searchname').on('click', function () {
                    var flag = true;
                    var href = window.location.href;
                    var startDate = $('#startDate').val();
                    var endDate = $('#endDate').val();
                    if (startDate == "" || endDate == "") {
                        alert("请选择时间区间");
                        return;
                    }
                    href = href.replace(/(startDate=.*?)(&|$|#)/, function () {
                        flag = false;
                        return 'startDate=' + startDate + arguments[2];
                    });
                    href = href.replace(/(endDate=.*?)(&|$|#)/, function () {
                        flag = false;
                        return 'endDate=' + endDate + arguments[2];
                    });
                    if (flag) {
                        // console.log(href.indexOf("?"));return;
                        if (href.indexOf("?") > 0) {
                            href += '&startDate=' + startDate + '&endDate=' + endDate;
                        } else {
                            href += '?startDate=' + startDate + '&endDate=' + endDate;
                        }
                    }

                    // window.location.href = href;
                    window.location.href = JustMarvel.potting.httpRequest.page(href);
                });
            },
            // 清空搜索条件（关键字搜索--1和时间段搜索--2）
            delSearch: function (type = 1) {
                var paramName = 'phname';
                if (type === 2) {
                    paramName = 'startDate';
                }
                $('#delSearch').on('click', function () {
                    var baseUrl = window.location.origin + window.location.pathname;
                    // 去除开头的'?'；
                    var query = window.location.search.substr(1);
                    var hash = window.location.hash;
                    if (query.indexOf(paramName) > -1) {
                        var obj = {};
                        var arr = query.split("&");
                        for (var i = 0; i < arr.length; i++) {
                            temp = arr[i].split("=");
                            obj[temp[0]] = temp[1];
                        }
                        delete obj[paramName];
                        if (type === 2) {
                            delete obj['endDate'];
                        }
                        var newQuery = JSON.stringify(obj).replace(/[\"\{\}]/g, "").replace(/\:/g, "=").replace(/\,/g, "&");
                        if (newQuery !== '') {
                            baseUrl += '?' + newQuery;
                        }
                        window.location.href = baseUrl;
                    }
                    //  else {
                    //     window.location.reload();
                    // };
                });
            }
        },
        pagination: {
            goto: function () {
                $('#gotoPage').on('click', function () {
                    var T = /^[1-9]\d*$/;
                    var target = $('#goto').val();

                    var currentPage = $(this).data('currentpage');
                    var lastPage = $(this).data('lastpage');

                    // console.log(currentPage);
                    var href = window.location.href;
                    if (T.test(target)) {
                        if (target > lastPage) {
                            alert("请输入合理页数");
                            return;
                        }
                        if (target == currentPage) {
                            alert("已处于" + target + "页");
                            return;
                        }
                        href = href.replace(/(page=.*?)(&|$|#)/, function () {
                            return 'page=' + target + arguments[2];
                        });
                        window.location.href = href;
                        return;
                    }

                    alert("请输入合理页数");
                });
            }
        },
    };

    JustMarvel.initialize = {
        init: function () {
            JustMarvel.initialize.showDate();
            //用户登录
            JustMarvel.initialize.user();
            JustMarvel.platform.init();
        },
        exdata: function () {
            $.ajax({
                url: "examples/widget1.json",
                type: "GET",
                dataType: "jsonp",
                success: function (data) {},
                error: function () {}
            });
        },
        showDate: function () {
            var datacontent = $(".systemdate"),
                oldday,
                newday;
            Date.prototype.format = function (fmt) { //author: meizz
                var o = {
                    "M+": this.getMonth() + 1, //月份
                    "d+": this.getDate(), //日
                    "h+": this.getHours(), //小时
                    "m+": this.getMinutes(), //分
                    "s+": this.getSeconds(), //秒
                    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                    "S": this.getMilliseconds() //毫秒
                };
                if (/(y+)/.test(fmt))
                    fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                for (var k in o)
                    if (new RegExp("(" + k + ")").test(fmt))
                        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                return fmt;
            };

            //oldday = new Date().toLocaleDateString();
            var showtime = self.setInterval(function () {
                datacontent.html(new Date().format("yyyy-MM-dd hh:mm:ss"));
                //newday = new Date().toLocaleDateString();
                // console.log(oldday,newday);
                //if (newday > oldday) {
                //    window.location.reload();
                //    // console.log(oldday,newday);
                //};
            }, 1000);
        },
        user: function () {
            // console.log($.cookie('login'), $.cookie('username'));
            if ($.cookie('login') == 'true' && $.cookie('username') != null) {
                $('.username').html($.cookie('username'));
            };

            $("#logout").on('click', function () {
                // console.log(1111);return;
                // 让 cookie 失效：$.cookie('right', 'undefined', {expires: new Date(Date.now() - 1000)});
                if(confirm("确认退出吗？")){
                    window.location.replace('/admin/login/logout');
                }

            });
        },
    };

    //后台框架
    JustMarvel.platform = {
        init: function () {
            JustMarvel.platform.frame();
            JustMarvel.platform.sideMenu();
            JustMarvel.platform.contentScorll();
            JustMarvel.platform.pageInit();

            //JustMarvel.platform.page();
        },
        frame: function () {
            $wrapper.width($window.width()).height($window.height());
        },
        sideMenu: function () {
            $(".aside-menu").height($(".aside-menu").height());
            $(".aside-menu").mCustomScrollbar({
                scrollButtons: {
                    enable: false,
                },
                autoHideScrollbar: true,
                theme: "light-thin"
            });

            $(".has-sub-menu").on('click', function (e) {
                e.stopPropagation();
                $(this).toggleClass('open');
                $(this).find('.sub-menu').slideToggle(300, 'easeInCubic');
                setTimeout(function () {
                    $(".aside-menu").mCustomScrollbar("update")
                }, 500);
            });
            $(".menu-item").on('click', function (e) {
                $(this).toggleClass('active');
                e.stopPropagation();
            });
        },
        contentScorll: function () {
            $("#sub-content").height($("#sub-content").height());
            $("#sub-content").mCustomScrollbar({
                scrollButtons: {
                    enable: false,
                },
                autoHideScrollbar: true,
                theme: "dark-thin"
            });
            //当内部有冒泡click事件，update滚动条
            $("#sub-content").on('click', function () {
                setTimeout(function () {
                    $("#sub-content").mCustomScrollbar("update")
                }, 500);
            });


        },
        //页面初始化
        pageInit: function () {
            if ($pageIndex.length > 0) {
                JustMarvel.platform.pageIndex.init();
            };
            if ($pageAccount.length > 0) {
                JustMarvel.platform.pageAccount.init();
            };
            if ($pageAccountGroup.length > 0) {
                JustMarvel.platform.pageAG.init();
            };
            if ($pageAgent.length > 0) {
                JustMarvel.platform.pageAgent.init();
            };
            if ($pageAgentGroup.length > 0) {
                JustMarvel.platform.pageAgentGroup.init();
            };
            if ($pageAgentLevel.length > 0) {
                JustMarvel.platform.pageAgentLevel.init();
            };
            if ($pageAgentReport.length > 0) {
                JustMarvel.platform.pageAgentReport.init();
            };
            if ($pageDevice.length > 0) {
                JustMarvel.platform.pageDevice.init();
            };
            if ($pageDeviceGroup.length > 0) {
                JustMarvel.platform.pageDeviceGroup.init();
            };
            if ($page4G.length > 0) {
                JustMarvel.platform.page4g.init();
            };
            if ($pageVideoLibrary.length > 0) {
                JustMarvel.platform.pageVideoLibrary.init();
            };
            if ($pageCarData.length > 0) {
                JustMarvel.platform.pageCarData.init();
            };
            if ($pageCarEvent.length > 0) {
                JustMarvel.platform.pageCarEvent.init();
            };
            if ($pageCarManage.length > 0) {
                JustMarvel.platform.pageCarManage.init();
            };
            if ($pageTask.length > 0) {
                JustMarvel.platform.pageTask.init();
            };
            if ($pageReceipt.length > 0) {
                JustMarvel.platform.pageReceipt.init();
            };
            if ($pageSN.length > 0) {
                JustMarvel.platform.pageSN.init();
            };
            if ($pageWrokOrder.length > 0) {
                JustMarvel.platform.pageWrokOrder.init();
            };
            if ($pageSystem.length > 0) {
                JustMarvel.platform.pageSystem.init();
            };
            if ($pageAdmin.length > 0) {
                JustMarvel.platform.pageAdmin.init();
            };

            // if ($menu.length > 0) {
            JustMarvel.platform.menu.init();
            // };

            if ($pageRules.length > 0) {
                JustMarvel.platform.pageRules.init();
            };

            if ($pageDocManage.length > 0) {
                JustMarvel.platform.pageDocManage.init();
            };

            if ($pageImageLibrary.length > 0) {
                JustMarvel.platform.pageImageLibrary.init();
            };

            if ($pageFeedback.length > 0) {
                JustMarvel.platform.pageFeedback.init();
            };

            if ($pageFaultrepair.length > 0) {
                JustMarvel.platform.pageFaultrepair.init();
            };
        },
    };

    //导航栏
    JustMarvel.platform.menu = {
        init: function () {
            // console.log("导航栏");
            JustMarvel.platform.menu.view();
        },
        view: function () {
            // console.log(menuController,$('.menu-item.'+ menuController).length);
            // console.log(('.has-sub-menu.'+menuController.toLowerCase()).find('ul.sub-menu').show());
            // $('.has-sub-menu.' + menuController.toLowerCase()).addClass('open').find('ul.sub-menu').show().find('.menu-item.' + menuController.toLowerCase()).addClass('active');
            $('.menu-item.' + menuController.toLowerCase()).addClass('active').parent().css('display', 'block').parent().addClass('open');

        },
    };
    //首页
    JustMarvel.platform.pageIndex = {
        init: function () {
            // console.log("主页");
            JustMarvel.platform.pageIndex.indexswiper();
            JustMarvel.platform.pageIndex.indexechart();
            JustMarvel.platform.pageIndex.goto();
        },
        indexswiper: function () {
            var shortcut = new Swiper('.swiper-shortcut', {
                direction: 'horizontal',
                loop: true,
                pagination: {
                    el: '.shortcut-pagination',
                    clickable: true,
                    bulletClass: 'index-bulletElement',
                },
            });
            var todolist = new Swiper('.swiper-todolist', {
                direction: 'horizontal',
                loop: true,
                pagination: {
                    el: '.todolist-pagination',
                    clickable: true,
                    bulletClass: 'index-bulletElement',
                },
            });
            var dataoverview = new Swiper('.swiper-dataoverview', {
                direction: 'horizontal',
                loop: true,
                pagination: {
                    el: '.dataoverview-pagination',
                    clickable: true,
                    bulletClass: 'index-bulletElement',
                },
            });
            var productnews = new Swiper('.swiper-productnews', {
                direction: 'horizontal',
                loop: true,
                pagination: {
                    el: '.productnews-pagination',
                    clickable: true,
                    bulletClass: 'index-bulletElement',
                },
            });
        },
        indexechart: function () {
            var chartOne = echarts.init(document.getElementById('chartOne')),
                optionOne = {
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            label: {
                                backgroundColor: '#6a7985',
                            }
                        },
                    },
                    legend: {
                        bottom: '10',
                        data: ['上海', '北京', '广州', '深圳', '武汉'],

                    },
                    gird: {
                        left: '0%',
                        right: '0%',
                        bottom: '3%',
                        containLabel: true,
                    },
                    xAxis: [{
                        type: 'category',
                        boundaryGap: false,
                        data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']
                    }],
                    yAxis: [{
                        type: 'value'
                    }],
                    series: [{
                            name: '上海',
                            type: 'line',
                            smooth: true,
                            areaStyle: {},
                            data: [120, 132, 101, 134, 90, 230, 210, 157, 87, 301, 354, 280],
                        },
                        {
                            name: '北京',
                            type: 'line',
                            smooth: true,
                            areaStyle: {},
                            data: [245, 282, 204, 283, 213, 219, 252, 108, 284, 225, 249, 228],
                        },
                        {
                            name: '广州',
                            type: 'line',
                            smooth: true,
                            areaStyle: {},
                            data: [233, 272, 222, 101, 172, 258, 195, 227, 134, 237, 161, 247],
                        },
                        {
                            name: '深圳',
                            type: 'line',
                            smooth: true,
                            areaStyle: {},
                            data: [259, 117, 272, 122, 153, 120, 112, 300, 103, 157, 216, 192],
                        },
                        {
                            name: '武汉',
                            type: 'line',
                            smooth: true,
                            areaStyle: {},
                            data: [258, 138, 167, 178, 122, 208, 133, 293, 228, 297, 279, 164],
                        },
                    ]
                };
            var chartTwo = echarts.init(document.getElementById('chartTwo')),
                optionTwo = {
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'horizontal',
                        bottom: '20',
                        data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
                    },
                    series: [{
                        name: '访问来源',
                        type: 'pie',
                        radius: '70%',
                        center: ['50%', '50%'],
                        data: [{
                                value: 335,
                                name: '直接访问'
                            },
                            {
                                value: 310,
                                name: '邮件营销'
                            },
                            {
                                value: 234,
                                name: '联盟广告'
                            },
                            {
                                value: 135,
                                name: '视频广告'
                            },
                            {
                                value: 1548,
                                name: '搜索引擎'
                            }
                        ],
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }]
                };
            var chartThree = echarts.init(document.getElementById('chartThree')),
                optionThree = {
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: { // 坐标轴指示器，坐标轴触发有效
                            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                        }
                    },
                    legend: {
                        data: ['活跃用户', '总注册用户', '离线用户']
                    },
                    grid: {
                        left: '0%',
                        right: '0%',
                        containLabel: true
                    },
                    xAxis: [{
                        type: 'value'
                    }],
                    yAxis: [{
                        type: 'category',
                        axisTick: {
                            show: false
                        },
                        data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
                    }],
                    series: [{
                            name: '活跃用户',
                            type: 'bar',
                            label: {
                                normal: {
                                    show: true,
                                    position: 'inside'
                                }
                            },
                            data: [200, 170, 240, 244, 200, 220, 210]
                        },
                        {
                            name: '总注册用户',
                            type: 'bar',
                            stack: '总量',
                            label: {
                                normal: {
                                    show: true
                                }
                            },
                            data: [320, 302, 341, 374, 390, 450, 420]
                        },
                        {
                            name: '离线用户',
                            type: 'bar',
                            stack: '总量',
                            label: {
                                normal: {
                                    show: true,
                                    position: 'left'
                                }
                            },
                            data: [-120, -132, -101, -134, -190, -230, -210]
                        }
                    ]
                };
            chartOne.setOption(optionOne);
            chartTwo.setOption(optionTwo);
            chartThree.setOption(optionThree);
        },
        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };
    //账户管理
    JustMarvel.platform.pageAccount = {
        init: function () {
            // console.log("账户管理");
            JustMarvel.platform.pageAccount.menu();
            JustMarvel.platform.pageAccount.dataInit();
            JustMarvel.platform.pageAccount.viewRecord();
            JustMarvel.platform.pageAccount.editRecord();
            JustMarvel.platform.pageAccount.delRecord();
            JustMarvel.platform.pageAccount.addRecord();
            JustMarvel.platform.pageAccount.batchDel();
            JustMarvel.platform.pageAccount.search();
            JustMarvel.platform.pageAccount.delSearch();
            JustMarvel.platform.pageAccount.goto();
        },
        menu: function () {

        },
        //数据初始化
        dataInit: function () {
            //$(".record-tool li a").on('click', function () {
            //    $("#edit-content").fadeToggle(300, 'easeInCubic');
            //});

        },
        //查看
        viewRecord: function () {
            $('.viewRecord').on('click', function () {
                var viewId = $(this).data('name');
                // console.log(viewId);
                //往后台传送数据
                $.ajax({
                    url: "/account/index",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            // console.log(data);
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view[0].id);
                            $("#accountname").val(data.view[0].username);
                            $("#nickname").val(data.view[0].nickname);
                            $("#last_login_at").val(data.view[0].last_login_at);
                            $("#email").val(data.view[0].email);
                            $("#integral").val(data.view[0].integral);
                            $("#created_at").val(data.view[0].created_at);
                            $("#devicecount").val(data.view[0].device_count);
                            $("#remark").val(data.view[0].remark);
                            $("#accountgroup").val(data.view[0].user_group_id);
                            $("#agent").val(data.view[0].franchiser_id);

                            $('.noedit').show();
                            //$('.noedit input').attr('disabled', 'disabled');

                            $('#viewRecord').find('input,select').attr("disabled", true); //disabled要在数据获取后添加，先写数据获取的方法，数据填充后VIEW操作，给所有INPUT，SELECT添加disabled
                            $('#viewRecord').modal('show'); //显示模态框
                            $(this).parents('tr').addClass('info'); //高亮选中行

                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });

            $('#viewRecord').on('hidden.bs.modal', function (e) {
                //这里要执行清除数据
                $('#viewRecord').find('input,select').attr("disabled", false); //要清除表单数据
                //添加的按钮需要清除
                $('#record-submit').remove();
                $('#record-add').remove();

                $('.data-table tr').removeClass('info'); //清除行高亮
            })
        },
        //编辑
        editRecord: function () {
            $('.editRecord').on('click', function () {
                var viewId = $(this).data('name');

                // console.log(viewId);
                //从接口查询数据
                $.ajax({
                    url: "/account/index",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view[0].id);
                            $("#accountgroup").val(data.view[0].user_group_id);
                            $("#agent").val(data.view[0].franchiser_id);
                            $("#remark").val(data.view[0].remark);

                            $(this).parents('tr').addClass('warning');
                            //这里先通过接口获取数据，获取数据后，添加编辑按钮
                            $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-submit\"><i class=\"fa fa-save\"></i>保存</a>");
                            $('#nocreate').hide();
                            $('#nocreate input').attr('disabled', 'disabled');
                            $('#noopen').hide();
                            $('#noopen input').attr('disabled', 'disabled');

                            $('.noedit').hide();
                            $('.noedit input').attr('disabled', 'disabled');
                            $('#viewRecord').modal('show');

                            //添加的提交按钮，绑定提交事件
                            $('#record-submit').on('click', function () {
                                // console.log($("#accountname").val());
                                var formdata = $("form[name=editForm]").serialize();
                                // console.log($("form[name=editForm]").serialize());

                                $.ajax({
                                    url: "/admin/account/edit?id=" + viewId,
                                    async: false,
                                    type: "post",
                                    data: formdata,
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.code == 200) {
                                            alert("修改成功");
                                            window.location.reload();
                                        } else {
                                            alert("修改失败");
                                        }
                                    }
                                })

                            });
                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });
            //模态框隐藏后事件
            $('#viewRecord').on('hidden.bs.modal', function () {
                $('#record-submit').remove();
                $('#record-add').remove();
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });

        },
        //删除
        delRecord: function () {
            $('.delRecord').on('click', function () {
                $(this).parents('tr').addClass('danger');
                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除该条记录吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });
                //获取要删除的id
                var deleId = $(this).data('name');

                //确认删除
                $('#confirm-del').on('click', function () {
                    // console.log(deleId);
                    $.ajax({
                        url: "/admin/account/delete?id=" + deleId,
                        async: false,
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("删除成功");
                                window.location.reload();
                            } else {
                                alert("删除失败");
                            }
                        }
                    })
                    $('#warning-message').alert('close');

                });
            });
        },
        //增加
        addRecord: function () {
            $('#addRecord').on('click', function () {
                // $(":input","form[name=editForm]").not(":button",":reset","hidden","submit").val("").removeAttr("checked").removeAttr("selected");
                $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-add\"><i class=\"fa fa-plus\"></i>添加</a>");
                $('#nocreate').hide();
                $('#nocreate input').attr('disabled', 'disabled');
                $('#noopen').hide();
                $('#noopen input').attr('disabled', 'disabled');
                $('.noedit').show();
                $('#viewRecord').modal('show');

                $('#record-add').on('click', function () {
                    //获取提交数据
                    var formdata = $("form[name=editForm]").serialize();
                    // console.log($("form[name=editForm]").serialize());

                    $.ajax({
                        url: "/admin/account/create",
                        async: false,
                        type: "post",
                        data: formdata,
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("添加成功");
                                window.location.reload();
                            } else {
                                alert("修改失败");
                            }
                        }
                    })
                })
            });

        },
        //批量删除
        batchDel: function () {
            //全选
            $("#selectAll").on("click", function () {
                if ($(this).prop("checked")) {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", true);

                } else {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", false);
                }
            });


            //操作删除
            $('#batchDel').on('click', function () {
                var checks = $(".data-table tbody input[type='checkbox']:checked");
                if (checks.length == 0) {
                    alert("请选择要删除的账户");
                    return;
                }
                // console.log(checks.length);
                //获取要删除的id
                var idArr = [];
                for (var i = 0; i < checks.length; i++) {
                    //checks[i].parent().next();
                    idArr.push($(checks[i]).parent().next().html());
                    // console.log($(checks[i]).parent().next().html());
                }
                // console.log(idArr);
                //return;

                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除这些账户吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //正式删除数据 传递数据给控制器
                $('#confirm-del').on('click', function () {
                    $.ajax({
                        url: "/admin/account/deleteArr",
                        async: false,
                        type: "post",
                        data: {
                            'id': idArr
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("批量删除成功");
                                window.location.reload();
                            } else {
                                alert("批量删除失败");
                            }
                        }
                    })
                })

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });

                //alert('批量删除');

            });
        },
        //搜索
        search: function () {
            JustMarvel.potting.search.searchByKeyword();
        },

        //清空搜索
        delSearch: function () {
            JustMarvel.potting.search.delSearch(1);
        },

        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };

    //账户组管理
    JustMarvel.platform.pageAG = {
        init: function () {
            // console.log("账户组管理");
            JustMarvel.platform.pageAG.menu();
            JustMarvel.platform.pageAG.dataInit();
            JustMarvel.platform.pageAG.addRecord();
            JustMarvel.platform.pageAG.editRecord();
            JustMarvel.platform.pageAG.delRecord();
            JustMarvel.platform.pageAG.batchDel();
            JustMarvel.platform.pageAG.goto();
        },
        menu: function () {

        },
        dataInit: function () {
            // $(".record-tool li a").on('click', function () {
            //     $("#edit-content").fadeToggle(300, 'easeInCubic');
            // });

        },
        //编辑
        editRecord: function () {
            $('.editRecord').on('click', function () {
                var editId = $(this).data('name');
                // console.log(editId);
                //从接口查询数据
                $.ajax({
                    url: "/accountgroup",
                    async: false,
                    type: "post",
                    data: {
                        'editId': editId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.edit.id);
                            $("#agname").val(data.edit.name);
                            $("#illustration").val(data.edit.illustration);
                            $("#weight").val(data.edit.weight);


                            $(this).parents('tr').addClass('warning');
                            //这里先通过接口获取数据，获取数据后，添加编辑按钮
                            $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-submit\"><i class=\"fa fa-save\"></i>保存</a>");
                            $('#viewRecord').modal('show');

                            //添加的提交按钮，绑定提交事件
                            $('#record-submit').on('click', function () {
                                // console.log(editId);
                                var formdata = $("form[name=editForm]").serialize();
                                // console.log($("form[name=editForm]").serialize());

                                $.ajax({
                                    url: "/admin/account_group/edit?id=" + editId,
                                    async: false,
                                    type: "post",
                                    data: formdata,
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.code == 200) {
                                            alert("修改成功");
                                            window.location.reload();
                                        } else {
                                            alert("修改失败");
                                        }
                                    }
                                })

                            });
                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });

                //模态框隐藏后事件
                $('#viewRecord').on('hidden.bs.modal', function () {
                    $('#record-submit').remove();
                    $('#record-add').remove();
                    $('.data-table tr').removeClass('warning'); //清除行高亮
                });

            });

        },
        //删除
        delRecord: function () {
            $('.delRecord').on('click', function () {
                $(this).parents('tr').addClass('danger');
                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除该条记录吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });
                //获取要删除的id
                var deleId = $(this).data('name');

                //确认删除
                $('#confirm-del').on('click', function () {
                    // console.log(deleId);
                    $.ajax({
                        url: "/admin/account_group/delete?id=" + deleId,
                        async: false,
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("删除成功");
                                window.location.reload();
                            } else {
                                alert("删除失败");
                            }
                        }
                    })
                    $('#warning-message').alert('close');

                });
            });
        },
        //增加
        addRecord: function () {
            $('#addRecord').on('click', function () {
                $(":input", "form[name=editForm]").not(":button", ":reset", "hidden", "submit").val("").removeAttr("checked").removeAttr("selected");
                $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-add\"><i class=\"fa fa-plus\"></i>添加</a>");
                $('#nocreate').hide();
                $('#nocreate input').attr('disabled', 'disabled');
                $('#viewRecord').modal('show');

                $('#record-add').on('click', function () {
                    //获取提交数据
                    var formdata = $("form[name=editForm]").serialize();
                    // console.log($("form[name=editForm]").serialize());

                    $.ajax({
                        url: "/admin/account_group/create",
                        async: false,
                        type: "post",
                        data: formdata,
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("添加成功");
                                window.location.reload();
                            } else {
                                alert("修改失败");
                            }
                        }
                    })
                })
            });

            $('#viewRecord').on('hidden.bs.modal', function (e) {
                //这里要执行清除数据
                $('#viewRecord').find('input,select').attr("disabled", false); //要清除表单数据
                //添加的按钮需要清除
                $('#record-submit').remove();
                $('#record-add').remove();

                $('.data-table tr').removeClass('info'); //清除行高亮
            })

        },
        //批量删除
        batchDel: function () {
            //全选
            $("#selectAll").on("click", function () {
                if ($(this).prop("checked")) {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", true);

                } else {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", false);
                }
            });


            //操作删除
            $('#batchDel').on('click', function () {
                var checks = $(".data-table tbody input[type='checkbox']:checked");
                if (checks.length == 0) {
                    alert("请选择要删除的账户");
                    return;
                }
                // console.log(checks.length);
                //获取要删除的id
                var idArr = [];
                for (var i = 0; i < checks.length; i++) {
                    //checks[i].parent().next();
                    idArr.push($(checks[i]).parent().next().html());
                    // console.log($(checks[i]).parent().next().html());
                }
                // console.log(idArr);
                //return;

                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除这些账户吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //正式删除数据 传递数据给控制器
                $('#confirm-del').on('click', function () {
                    $.ajax({
                        url: "/admin/account_group/deleteArr",
                        async: false,
                        type: "post",
                        data: {
                            'id': idArr
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("批量删除成功");
                                window.location.reload();
                            } else {
                                alert("批量删除失败");
                            }
                        }
                    })
                })

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });

                //alert('批量删除');

            });
        },
        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };

    //代理商管理
    JustMarvel.platform.pageAgent = {
        init: function () {
            // console.log("代理商管理");
            JustMarvel.platform.pageAgent.menu();
            JustMarvel.platform.pageAgent.dataInit();
            JustMarvel.platform.pageAgent.viewRecord();
            JustMarvel.platform.pageAgent.editRecord();
            JustMarvel.platform.pageAgent.delRecord();
            JustMarvel.platform.pageAgent.addRecord();
            JustMarvel.platform.pageAgent.batchDel();
            JustMarvel.platform.pageAgent.search();
            JustMarvel.platform.pageAgent.goto();
        },
        menu: function () {

        },
        dataInit: function () {
            // $(".record-tool li a").on('click', function () {
            //     $("#edit-content").fadeToggle(300, 'easeInCubic');
            // });
        },
        //查看
        viewRecord: function () {
            $('.viewRecord').on('click', function () {
                var viewId = $(this).data('name');
                // console.log(viewId);
                //往后台传送数据
                $.ajax({
                    url: "/agent",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            // console.log(data);
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#code").val(data.view.code);
                            //$("#admin_group_id").val(data.view.admin_group_id);
                            $("#agentname").val(data.view.name);
                            $("#linkman").val(data.view.linkman);
                            $("#mobile").val(data.view.mobile);
                            $("#province").val(data.view.province);
                            var city = $("select[name='city']");
                            for(var i=0;i<data.arrpro.length;i++){
                                city.append(
                                    "<option value='"+data.arrpro[i]['id']+"'>" + data.arrpro[i]['name']
                                    + "</option>");
                            }
                            $("#city").val(data.view.city);

                            var area = $("select[name='area']");
                            for(var i=0;i<data.arrcity.length;i++){
                                area.append(
                                    "<option value='"+data.arrcity[i]['id']+"'>" + data.arrcity[i]['name']
                                    + "</option>");
                            }
                            $("#area").val(data.view.area);

                            $("#franchiser_group_id").val(data.view.franchiser_group_id);
                            $("#franchiser_level_id").val(data.view.franchiser_level_id);

                            $('#viewRecord').find('input,select').attr("disabled", true); //disabled要在数据获取后添加，先写数据获取的方法，数据填充后VIEW操作，给所有INPUT，SELECT添加disabled
                            $('#viewRecord').modal('show'); //显示模态框
                            $(this).parents('tr').addClass('info'); //高亮选中行

                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });

            $('#viewRecord').on('hidden.bs.modal', function (e) {
                //这里要执行清除数据
                $('#viewRecord').find('input,select').attr("disabled", false); //要清除表单数据
                //添加的按钮需要清除
                $('#record-submit').remove();
                $('#record-add').remove();

                $('.data-table tr').removeClass('info'); //清除行高亮
            })
        },
        //编辑
        editRecord: function () {
            $('.editRecord').on('click', function () {
                var viewId = $(this).data('name');
                // console.log(viewId);
                //从接口查询数据
                $.ajax({
                    url: "/agent",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#code").val(data.view.code);
                            $("#agentname").val(data.view.name);
                            //$("#admin_group_id").val(data.view.admin_group_id);
                            $("#linkman").val(data.view.linkman);
                            $("#mobile").val(data.view.mobile);

                            $("#province").val(data.view.province);
                            var city = $("select[name='city']");
                            for(var i=0;i<data.arrpro.length;i++){
                                city.append(
                                    "<option value='"+data.arrpro[i]['id']+"'>" + data.arrpro[i]['name']
                                    + "</option>");
                            }
                            $("#city").val(data.view.city);

                            var area = $("select[name='area']");
                            for(var i=0;i<data.arrcity.length;i++){
                                area.append(
                                    "<option value='"+data.arrcity[i]['id']+"'>" + data.arrcity[i]['name']
                                    + "</option>");
                            }
                            $("#area").val(data.view.area);



                            $("#franchiser_group_id").val(data.view.franchiser_group_id);
                            $("#franchiser_level_id").val(data.view.franchiser_level_id);

                            $(this).parents('tr').addClass('warning');
                            //这里先通过接口获取数据，获取数据后，添加编辑按钮
                            $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-submit\"><i class=\"fa fa-save\"></i>保存</a>");
                            $('#viewRecord').modal('show');

                            //添加的提交按钮，绑定提交事件
                            $('#record-submit').on('click', function () {
                                // console.log($("#accountname").val());
                                var formdata = $("form[name=editForm]").serialize();
                                // console.log($("form[name=editForm]").serialize());

                                $.ajax({
                                    url: "/admin/agent/edit?id=" + viewId,
                                    async: false,
                                    type: "post",
                                    data: formdata,
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.code == 200) {
                                            alert("修改成功");
                                            window.location.reload();
                                        } else {
                                            alert("修改失败");
                                        }
                                    }
                                })

                            });
                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });
            //模态框隐藏后事件
            $('#viewRecord').on('hidden.bs.modal', function () {
                $('#record-submit').remove();
                $('#record-add').remove();
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });

        },
        //删除
        delRecord: function () {
            $('.delRecord').on('click', function () {
                $(this).parents('tr').addClass('danger');
                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除该条记录吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });
                //获取要删除的id
                var deleId = $(this).data('name');

                //确认删除
                $('#confirm-del').on('click', function () {
                    // console.log(deleId);
                    $.ajax({
                        url: "/admin/agent/delete?id=" + deleId,
                        async: false,
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("删除成功");
                                window.location.reload();
                            } else {
                                alert("删除失败");
                            }
                        }
                    })
                    $('#warning-message').alert('close');

                });
            });
        },
        //增加
        addRecord: function () {
            $('#addRecord').on('click', function () {
                $(":input", "form[name=editForm]").not(":button", ":reset", "hidden", "submit").val("").removeAttr("checked").removeAttr("selected");
                $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-add\"><i class=\"fa fa-plus\"></i>添加</a>");
                $('#nocreate').hide();
                $('#nocreate input').attr('disabled', 'disabled');
                $('#viewRecord').modal('show');

                $('#record-add').on('click', function () {
                    //获取提交数据
                    var formdata = $("form[name=editForm]").serialize();
                    // console.log($("form[name=editForm]").serialize());

                    $.ajax({
                        url: "/admin/agent/create",
                        async: false,
                        type: "post",
                        data: formdata,
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("添加成功");
                                window.location.reload();
                            } else {
                                alert("修改失败");
                            }
                        }
                    })
                })
            });

        },
        //批量删除
        batchDel: function () {
            //全选
            $("#selectAll").on("click", function () {
                if ($(this).prop("checked")) {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", true);

                } else {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", false);
                }
            });


            //操作删除
            $('#batchDel').on('click', function () {
                var checks = $(".data-table tbody input[type='checkbox']:checked");
                if (checks.length == 0) {
                    alert("请选择要删除的账户");
                    return;
                }
                // console.log(checks.length);
                //获取要删除的id
                var idArr = [];
                for (var i = 0; i < checks.length; i++) {
                    //checks[i].parent().next();
                    idArr.push($(checks[i]).parent().next().html());
                    // console.log($(checks[i]).parent().next().html());
                }
                // console.log(idArr);
                //return;

                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除这些账户吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //正式删除数据 传递数据给控制器
                $('#confirm-del').on('click', function () {
                    $.ajax({
                        url: "/admin/agent/deleteArr",
                        async: false,
                        type: "post",
                        data: {
                            'id': idArr
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("批量删除成功");
                                window.location.reload();
                            } else {
                                alert("批量删除失败");
                            }
                        }
                    })
                })

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });

                //alert('批量删除');

            });
        },
        //搜索
        search: function () {
            JustMarvel.potting.search.searchByKeyword();
        },
        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };

    //代理商组管理
    JustMarvel.platform.pageAgentGroup = {
        init: function () {
            // console.log("代理商组管理");
            JustMarvel.platform.pageAgentGroup.menu();
            JustMarvel.platform.pageAgentGroup.dataInit();
            JustMarvel.platform.pageAgentGroup.addRecord();
            JustMarvel.platform.pageAgentGroup.editRecord();
            JustMarvel.platform.pageAgentGroup.delRecord();
            JustMarvel.platform.pageAgentGroup.batchDel();
            JustMarvel.platform.pageAgentGroup.goto();
        },
        menu: function () {

        },
        dataInit: function () {
            $(".record-tool li a").on('click', function () {
                $("#edit-content").fadeToggle(300, 'easeInCubic');
            });

        },

        //编辑
        editRecord: function () {
            $('.editRecord').on('click', function () {
                var viewId = $(this).data('name');
                // console.log(viewId);
                //从接口查询数据
                $.ajax({
                    url: "/agentgroup",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#name").val(data.view.name);
                            $("#illustration").val(data.view.illustration);
                            $("#weight").val(data.view.weight);

                            $(this).parents('tr').addClass('warning');
                            //这里先通过接口获取数据，获取数据后，添加编辑按钮
                            $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-submit\"><i class=\"fa fa-save\"></i>保存</a>");
                            $('#viewRecord').modal('show');

                            //添加的提交按钮，绑定提交事件
                            $('#record-submit').on('click', function () {
                                // console.log($("#accountname").val());
                                var formdata = $("form[name=editForm]").serialize();
                                // console.log($("form[name=editForm]").serialize());

                                $.ajax({
                                    url: "/admin/agent_group/edit?id=" + viewId,
                                    async: false,
                                    type: "post",
                                    data: formdata,
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.code == 200) {
                                            alert("修改成功");
                                            window.location.reload();
                                        } else {
                                            alert("修改失败");
                                        }
                                    }
                                })

                            });
                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });
            //模态框隐藏后事件
            $('#viewRecord').on('hidden.bs.modal', function () {
                $('#record-submit').remove();
                $('#record-add').remove();
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });

        },
        //删除
        delRecord: function () {
            $('.delRecord').on('click', function () {
                $(this).parents('tr').addClass('danger');
                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除该条记录吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });
                //获取要删除的id
                var deleId = $(this).data('name');

                //确认删除
                $('#confirm-del').on('click', function () {
                    // console.log(deleId);
                    $.ajax({
                        url: "/admin/agent_group/delete?id=" + deleId,
                        async: false,
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("删除成功");
                                window.location.reload();
                            } else {
                                alert("删除失败");
                            }
                        }
                    })
                    $('#warning-message').alert('close');

                });
            });
        },
        //增加
        addRecord: function () {
            $('#addRecord').on('click', function () {
                $(":input", "form[name=editForm]").not(":button", ":reset", "hidden", "submit").val("").removeAttr("checked").removeAttr("selected");
                $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-add\"><i class=\"fa fa-plus\"></i>添加</a>");
                $('#nocreate').hide();
                $('#nocreate input').attr('disabled', 'disabled');
                $('#viewRecord').modal('show');

                $('#record-add').on('click', function () {
                    //获取提交数据
                    var formdata = $("form[name=editForm]").serialize();
                    // console.log($("form[name=editForm]").serialize());

                    $.ajax({
                        url: "/admin/agent_group/create",
                        async: false,
                        type: "post",
                        data: formdata,
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("添加成功");
                                window.location.reload();
                            } else {
                                alert("修改失败");
                            }
                        }
                    })
                })
            });

            $('#viewRecord').on('hidden.bs.modal', function (e) {
                //这里要执行清除数据
                $('#viewRecord').find('input,select').attr("disabled", false); //要清除表单数据
                //添加的按钮需要清除
                $('#record-submit').remove();
                $('#record-add').remove();

                $('.data-table tr').removeClass('info'); //清除行高亮
            })
        },
        //批量删除
        batchDel: function () {
            //全选
            $("#selectAll").on("click", function () {
                if ($(this).prop("checked")) {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", true);

                } else {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", false);
                }
            });

            //操作删除
            $('#batchDel').on('click', function () {
                var checks = $(".data-table tbody input[type='checkbox']:checked");
                if (checks.length == 0) {
                    alert("请选择要删除的账户");
                    return;
                }
                // console.log(checks.length);
                //获取要删除的id
                var idArr = [];
                for (var i = 0; i < checks.length; i++) {
                    //checks[i].parent().next();
                    idArr.push($(checks[i]).parent().next().html());
                    // console.log($(checks[i]).parent().next().html());
                }
                // console.log(idArr);
                //return;

                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除这些账户吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //正式删除数据 传递数据给控制器
                $('#confirm-del').on('click', function () {
                    $.ajax({
                        url: "/admin/agent_group/deleteArr",
                        async: false,
                        type: "post",
                        data: {
                            'id': idArr
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("批量删除成功");
                                window.location.reload();
                            } else {
                                alert("批量删除失败");
                            }
                        }
                    })
                })

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });

                //alert('批量删除');

            });
        },
        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }

    };

    //代理商级别管理
    JustMarvel.platform.pageAgentLevel = {
        init: function () {
            // console.log("代理商组管理");
            JustMarvel.platform.pageAgentLevel.menu();
            JustMarvel.platform.pageAgentLevel.dataInit();
            JustMarvel.platform.pageAgentLevel.addRecord();
            JustMarvel.platform.pageAgentLevel.editRecord();
            JustMarvel.platform.pageAgentLevel.delRecord();
            JustMarvel.platform.pageAgentLevel.batchDel();
            JustMarvel.platform.pageAgentLevel.goto();
        },
        menu: function () {

        },
        dataInit: function () {
            $(".record-tool li a").on('click', function () {
                $("#edit-content").fadeToggle(300, 'easeInCubic');
            });

        },

        //编辑
        editRecord: function () {
            $('.editRecord').on('click', function () {
                var viewId = $(this).data('name');
                // console.log(viewId);
                //从接口查询数据
                $.ajax({
                    url: "/agentlevel",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#name").val(data.view.name);
                            $("#illustration").val(data.view.illustration);

                            $(this).parents('tr').addClass('warning');
                            //这里先通过接口获取数据，获取数据后，添加编辑按钮
                            $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-submit\"><i class=\"fa fa-save\"></i>保存</a>");
                            $('#viewRecord').modal('show');

                            //添加的提交按钮，绑定提交事件
                            $('#record-submit').on('click', function () {
                                // console.log($("#accountname").val());
                                var formdata = $("form[name=editForm]").serialize();
                                // console.log($("form[name=editForm]").serialize());

                                $.ajax({
                                    url: "/admin/agent_level/edit?id=" + viewId,
                                    async: false,
                                    type: "post",
                                    data: formdata,
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.code == 200) {
                                            alert("修改成功");
                                            window.location.reload();
                                        } else {
                                            alert("修改失败");
                                        }
                                    }
                                })

                            });
                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });
            //模态框隐藏后事件
            $('#viewRecord').on('hidden.bs.modal', function () {
                $('#record-submit').remove();
                $('#record-add').remove();
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });

        },
        //删除
        delRecord: function () {
            $('.delRecord').on('click', function () {
                $(this).parents('tr').addClass('danger');
                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除该条记录吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });
                //获取要删除的id
                var deleId = $(this).data('name');

                //确认删除
                $('#confirm-del').on('click', function () {
                    // console.log(deleId);
                    $.ajax({
                        url: "/admin/agent_level/delete?id=" + deleId,
                        async: false,
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("删除成功");
                                window.location.reload();
                            } else {
                                alert("删除失败");
                            }
                        }
                    })
                    $('#warning-message').alert('close');

                });
            });
        },
        //增加
        addRecord: function () {
            $('#addRecord').on('click', function () {
                $(":input", "form[name=editForm]").not(":button", ":reset", "hidden", "submit").val("").removeAttr("checked").removeAttr("selected");
                $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-add\"><i class=\"fa fa-plus\"></i>添加</a>");
                $('#nocreate').hide();
                $('#nocreate input').attr('disabled', 'disabled');
                $('#viewRecord').modal('show');

                $('#record-add').on('click', function () {
                    //获取提交数据
                    var formdata = $("form[name=editForm]").serialize();
                    // console.log($("form[name=editForm]").serialize());

                    $.ajax({
                        url: "/admin/agent_level/create",
                        async: false,
                        type: "post",
                        data: formdata,
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("添加成功");
                                window.location.reload();
                            } else {
                                alert("修改失败");
                            }
                        }
                    })
                })
            });

            $('#viewRecord').on('hidden.bs.modal', function (e) {
                //这里要执行清除数据
                $('#viewRecord').find('input,select').attr("disabled", false); //要清除表单数据
                //添加的按钮需要清除
                $('#record-submit').remove();
                $('#record-add').remove();

                $('.data-table tr').removeClass('info'); //清除行高亮
            })
        },
        //批量删除
        batchDel: function () {
            //全选
            $("#selectAll").on("click", function () {
                if ($(this).prop("checked")) {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", true);

                } else {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", false);
                }
            });

            //操作删除
            $('#batchDel').on('click', function () {
                var checks = $(".data-table tbody input[type='checkbox']:checked");
                if (checks.length == 0) {
                    alert("请选择要删除的账户");
                    return;
                }
                // console.log(checks.length);
                //获取要删除的id
                var idArr = [];
                for (var i = 0; i < checks.length; i++) {
                    //checks[i].parent().next();
                    idArr.push($(checks[i]).parent().next().html());
                    // console.log($(checks[i]).parent().next().html());
                }
                // console.log(idArr);
                //return;

                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除这些账户吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //正式删除数据 传递数据给控制器
                $('#confirm-del').on('click', function () {
                    $.ajax({
                        url: "/admin/agent_level/deleteArr",
                        async: false,
                        type: "post",
                        data: {
                            'id': idArr
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("批量删除成功");
                                window.location.reload();
                            } else {
                                alert("批量删除失败");
                            }
                        }
                    })
                })

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });

                //alert('批量删除');

            });
        },
        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }

    };

    //代理商数据报告
    JustMarvel.platform.pageAgentReport = {
        init: function () {
            // console.log("代理商数据报告");
            JustMarvel.platform.pageAgentReport.menu();
            JustMarvel.platform.pageAgentReport.subreport();
            JustMarvel.platform.pageAgentReport.dataInit();
            JustMarvel.platform.pageAgentReport.goto();
        },
        menu: function () {

        },
        subreport: function () {
            var names = [];
            var values = [];
            var datainfo = [];
            $.ajax({
                type: "post",
                async:false,
                url: "/admin/agent_report/echartsdata",
                data: "data",
                dataType: "json",
                success: function (data) {
                    //console.log(data.data);
                    for (i = 0; i < data.data.length; i++) {
                        names.push(data.data[i].name);
                        values.push(data.data[i].value);
                        datainfo.push({
                            value: values[i],
                            name: names[i],
                        });
                    };
                    //console.log(datainfo);
                },
            });
            //console.log(datainfo);
            var subchart = echarts.init(document.getElementById('sub-report')),
                optionsubchart = {
                    title: {
                        text: '经销商统计',
                        //subtext: '纯属虚构',
                        x: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        top: '80',
                        right: '100',
                        //data: ['北京市', '天津市', '上海市', '江苏省', '浙江省', '安徽省', '福建省', '江西省', '湖南省', '山东省', '河南省', '内蒙古自治区', '湖北省', '宁夏回族自治区', '新疆维吾尔自治区', '广东省', '西藏自治区', '海南省', '广西壮族自治区', '四川省', '河北省', '贵州省', '重庆市', '山西省', '云南省', '辽宁省', '陕西省', '吉林省', '甘肃省', '黑龙江省', '青海省', '台湾省', '香港特别行政区', '澳门特别行政区']
                    },
                    series: [{
                        name: '代理商数量',
                        type: 'pie',
                        radius: '80%',
                        center: ['50%', '55%'],
                        data: datainfo,
                        label:{
                            show:false,
                        },
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }

                    }]
                };

            subchart.setOption(optionsubchart);
        },
        dataInit: function () {
            // $(".record-tool li a").on('click', function () {
            //     $("#edit-content").fadeToggle(300, 'easeInCubic');
            // });

        },
        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };

    //设备管理
    JustMarvel.platform.pageDevice = {
        init: function () {
            // console.log("设备管理");
            JustMarvel.platform.pageDevice.menu();
            JustMarvel.platform.pageDevice.dataInit();
            JustMarvel.platform.pageDevice.viewRecord();
            JustMarvel.platform.pageDevice.editRecord();
            JustMarvel.platform.pageDevice.delRecord();
            JustMarvel.platform.pageDevice.addRecord();
            JustMarvel.platform.pageDevice.batchDel();
            JustMarvel.platform.pageDevice.search();
            JustMarvel.platform.pageDevice.delSearch();
            JustMarvel.platform.pageDevice.goto();
        },
        menu: function () {

        },
        dataInit: function () {
            $(".record-tool li a").on('click', function () {
                $("#edit-content").fadeToggle(300, 'easeInCubic');
            });

        },
        //查看
        viewRecord: function () {
            $('.viewRecord').on('click', function () {
                var viewId = $(this).data('name');
                // console.log(viewId);
                //往后台传送数据
                $.ajax({
                    url: "/device",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            // console.log(data);
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#sn_id").val(data.view.sn_id);
                            $("#user_id").val(data.view.user_id);
                            $("#sim").val(data.view.sim);
                            $("#imei").val(data.view.imei);
                            //$("#car_model").val(data.view.car_model);
                            // $("#longitude").val(data.view.longitude);
                            //  $("#latitude").val(data.view.latitude);
                            //  $("#radius").val(data.view.radius);
                            // $("#car_brand").val(data.view.car_brand);
                            // console.log(data.view.imei);
                            $("#iccid").val(data.view.iccid);
                            if (data.view.state == 1) {
                                $(".state.s1").attr("checked", 'checked');
                            } else {
                                $(".state.s0").attr("checked", 'checked');
                            }
                            $("#name").val(data.view.name);
                            // $("#device_model_id").val(data.view.device_model_id);
                            $("#device_group_id").val(data.view.device_group_id);
                            // $("#franchiser_id").val(data.view.franchiser_id);

                            $('#viewRecord').find('input,select').attr("disabled", true); //disabled要在数据获取后添加，先写数据获取的方法，数据填充后VIEW操作，给所有INPUT，SELECT添加disabled
                            $('#viewRecord').modal('show'); //显示模态框
                            $(this).parents('tr').addClass('info'); //高亮选中行

                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });

            $('#viewRecord').on('hidden.bs.modal', function (e) {
                //这里要执行清除数据
                $('#viewRecord').find('input,select').attr("disabled", false); //要清除表单数据
                //添加的按钮需要清除
                $('#record-submit').remove();
                $('#record-add').remove();

                $('.data-table tr').removeClass('info'); //清除行高亮
            })
        },
        //编辑
        editRecord: function () {
            $('.editRecord').on('click', function () {
                var viewId = $(this).data('name');
                // console.log(viewId);
                //从接口查询数据
                $.ajax({
                    url: "/device",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#sn_id").val(data.view.sn_id);
                            $("#user_id").val(data.view.user_id);
                            $("#sim").val(data.view.sim);
                            $("#imei").val(data.view.imei);
                            $("#car_model").val(data.view.car_model);
                            $("#car_brand").val(data.view.car_brand);
                            // console.log(data.view.imei);
                            $("#iccid").val(data.view.iccid);
                            if (data.view.status == 1) {
                                $(".state.s1").attr("checked", 'checked');
                            } else {
                                $(".state.s0").attr("checked", 'checked');
                            }
                            $("#name").val(data.view.name);
                            $("#device_model_id").val(data.view.device_model_id);
                            $("#device_group_id").val(data.view.device_group_id);
                            $("#franchiser_id").val(data.view.franchiser_id);

                            $(this).parents('tr').addClass('warning');

                            $('#fence').find('input,select').attr("disabled", true);
                            //这里先通过接口获取数据，获取数据后，添加编辑按钮
                            $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-submit\"><i class=\"fa fa-save\"></i>保存</a>");
                            $('#viewRecord').modal('show');

                            //添加的提交按钮，绑定提交事件
                            $('#record-submit').on('click', function () {
                                // console.log($("#accountname").val());
                                var formdata = $("form[name=editForm]").serialize();
                                // console.log($("form[name=editForm]").serialize());

                                $.ajax({
                                    url: "/admin/device/edit?id=" + viewId,
                                    async: false,
                                    type: "post",
                                    data: formdata,
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.code == 200) {
                                            alert("修改成功");
                                            window.location.reload();
                                        } else {
                                            alert("修改失败");
                                        }
                                    }
                                })

                            });
                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });
            //模态框隐藏后事件
            $('#viewRecord').on('hidden.bs.modal', function () {
                $('#record-submit').remove();
                $('#record-add').remove();
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });

        },
        //删除
        delRecord: function () {
            $('.delRecord').on('click', function () {
                $(this).parents('tr').addClass('danger');
                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除该条记录吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });
                //获取要删除的id
                var deleId = $(this).data('name');

                //确认删除
                $('#confirm-del').on('click', function () {
                    // console.log(deleId);
                    $.ajax({
                        url: "/admin/device/delete?id=" + deleId,
                        async: false,
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("删除成功");
                                window.location.reload();
                            } else {
                                alert("删除失败");
                            }
                        }
                    })
                    $('#warning-message').alert('close');

                });
            });
        },
        //增加
        addRecord: function () {
            $('#addRecord').on('click', function () {
                $(":input", "form[name=editForm]").not(":button", ":reset", "hidden", "submit").val("").removeAttr("checked").removeAttr("selected");
                $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-add\"><i class=\"fa fa-plus\"></i>添加</a>");
                $('#nocreate').hide();
                $('#nocreate input').attr('disabled', 'disabled');
                $('#viewRecord').modal('show');

                $('#record-add').on('click', function () {
                    //获取提交数据
                    var formdata = $("form[name=editForm]").serialize();
                    // console.log($("form[name=editForm]").serialize());

                    $.ajax({
                        url: "/admin/device/create",
                        async: false,
                        type: "post",
                        data: formdata,
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("添加成功");
                                window.location.reload();
                            } else {
                                alert("修改失败");
                            }
                        }
                    })
                })
            });

        },

        //批量删除
        batchDel: function () {
            //全选
            $("#selectAll").on("click", function () {
                if ($(this).prop("checked")) {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", true);

                } else {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", false);
                }
            });


            //操作删除
            $('#batchDel').on('click', function () {
                var checks = $(".data-table tbody input[type='checkbox']:checked");
                if (checks.length == 0) {
                    alert("请选择要删除的账户");
                    return;
                }
                // console.log(checks.length);
                //获取要删除的id
                var idArr = [];
                for (var i = 0; i < checks.length; i++) {
                    //checks[i].parent().next();
                    idArr.push($(checks[i]).parent().next().html());
                    // console.log($(checks[i]).parent().next().html());
                }
                // console.log(idArr);
                //return;

                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除这些账户吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //正式删除数据 传递数据给控制器
                $('#confirm-del').on('click', function () {
                    $.ajax({
                        url: "/admin/device/deleteArr",
                        async: false,
                        type: "post",
                        data: {
                            'id': idArr
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("批量删除成功");
                                window.location.reload();
                            } else {
                                alert("批量删除失败");
                            }
                        }
                    })
                })

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });

                //alert('批量删除');

            });
        },

        //搜索
        search: function () {
            $("#Scondition").change(function () {
                /* var firstValue = $("#Scondition option").val();
                 console.log(firstValue);*/
                $("#phname").show();
                JustMarvel.potting.search.searchByKeyword();
            });

        },

        //清空搜索
        delSearch: function () {
            JustMarvel.potting.search.delSearch(1);
            //$("#phname").hide();
        },

        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };

    //设备组管理
    JustMarvel.platform.pageDeviceGroup = {
        init: function () {
            // console.log("设备组管理");
            JustMarvel.platform.pageDeviceGroup.menu();
            JustMarvel.platform.pageDeviceGroup.dataInit();
            JustMarvel.platform.pageDeviceGroup.addRecord();
            JustMarvel.platform.pageDeviceGroup.editRecord();
            JustMarvel.platform.pageDeviceGroup.delRecord();
            JustMarvel.platform.pageDeviceGroup.batchDel();
            JustMarvel.platform.pageDeviceGroup.goto();
        },
        menu: function () {

        },
        dataInit: function () {
            $(".record-tool li a").on('click', function () {
                $("#edit-content").fadeToggle(300, 'easeInCubic');
            });

        },
        //编辑
        editRecord: function () {
            $('.editRecord').on('click', function () {
                var viewId = $(this).data('name');
                // console.log(viewId);
                //从接口查询数据
                $.ajax({
                    url: "/devicegroup",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#name").val(data.view.name);
                            $("#illustration").val(data.view.illustration);
                            $("#weight").val(data.view.weight);


                            $(this).parents('tr').addClass('warning');
                            //这里先通过接口获取数据，获取数据后，添加编辑按钮
                            $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-submit\"><i class=\"fa fa-save\"></i>保存</a>");
                            $('#viewRecord').modal('show');

                            //添加的提交按钮，绑定提交事件
                            $('#record-submit').on('click', function () {
                                // console.log($("#accountname").val());
                                var formdata = $("form[name=editForm]").serialize();
                                // console.log($("form[name=editForm]").serialize());

                                $.ajax({
                                    url: "/admin/device_group/edit?id=" + viewId,
                                    async: false,
                                    type: "post",
                                    data: formdata,
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.code == 200) {
                                            alert("修改成功");
                                            window.location.reload();
                                        } else {
                                            alert("修改失败");
                                        }
                                    }
                                })

                            });
                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });
            //模态框隐藏后事件
            $('#viewRecord').on('hidden.bs.modal', function () {
                $('#record-submit').remove();
                $('#record-add').remove();
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });

        },
        //删除
        delRecord: function () {
            $('.delRecord').on('click', function () {
                $(this).parents('tr').addClass('danger');
                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除该条记录吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });
                //获取要删除的id
                var deleId = $(this).data('name');

                //确认删除
                $('#confirm-del').on('click', function () {
                    // console.log(deleId);
                    $.ajax({
                        url: "/admin/device_group/delete?id=" + deleId,
                        async: false,
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("删除成功");
                                window.location.reload();
                            } else {
                                alert("删除失败");
                            }
                        }
                    })
                    $('#warning-message').alert('close');

                });
            });
        },
        //增加
        addRecord: function () {
            $('#addRecord').on('click', function () {
                $(":input", "form[name=editForm]").not(":button", ":reset", "hidden", "submit").val("").removeAttr("checked").removeAttr("selected");
                $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-add\"><i class=\"fa fa-plus\"></i>添加</a>");
                $('#nocreate').hide();
                $('#nocreate input').attr('disabled', 'disabled');
                $('#viewRecord').modal('show');

                $('#record-add').on('click', function () {
                    //获取提交数据
                    var formdata = $("form[name=editForm]").serialize();
                    // console.log($("form[name=editForm]").serialize());

                    $.ajax({
                        url: "/admin/device_group/create",
                        async: false,
                        type: "post",
                        data: formdata,
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("添加成功");
                                window.location.reload();
                            } else {
                                alert("修改失败");
                            }
                        }
                    })
                })
            });

        },
        //批量删除
        batchDel: function () {
            //全选
            $("#selectAll").on("click", function () {
                if ($(this).prop("checked")) {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", true);

                } else {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", false);
                }
            });


            //操作删除
            $('#batchDel').on('click', function () {
                var checks = $(".data-table tbody input[type='checkbox']:checked");
                if (checks.length == 0) {
                    alert("请选择要删除的账户");
                    return;
                }
                // console.log(checks.length);
                //获取要删除的id
                var idArr = [];
                for (var i = 0; i < checks.length; i++) {
                    //checks[i].parent().next();
                    idArr.push($(checks[i]).parent().next().html());
                    // console.log($(checks[i]).parent().next().html());
                }
                // console.log(idArr);
                //return;

                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除这些账户吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //正式删除数据 传递数据给控制器
                $('#confirm-del').on('click', function () {
                    $.ajax({
                        url: "/admin/device_group/deleteArr",
                        async: false,
                        type: "post",
                        data: {
                            'id': idArr
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("批量删除成功");
                                window.location.reload();
                            } else {
                                alert("批量删除失败");
                            }
                        }
                    })
                })

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });

                //alert('批量删除');

            });
        },
        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };

    //4G流量管理
    JustMarvel.platform.page4g = {
        init: function () {
            // console.log("4G流量管理");
            JustMarvel.platform.page4g.menu();
            JustMarvel.platform.page4g.dataInit();
            JustMarvel.platform.page4g.viewRecord();
            JustMarvel.platform.page4g.recharge();
            JustMarvel.platform.page4g.addRecord();
            JustMarvel.platform.page4g.batchDel();
            JustMarvel.platform.page4g.search();
            JustMarvel.platform.page4g.delSearch();
            JustMarvel.platform.page4g.goto();
        },
        menu: function () {

        },
        dataInit: function () {
            $(".record-tool li a").on('click', function () {
                $("#edit-content").fadeToggle(300, 'easeInCubic');
            });
        },

        recharge: function () {

        },

        //查看
        viewRecord: function () {
            $('.viewRecord').on('click', function () {
                var viewId = $(this).data('name');
                // console.log(viewId);
                //往后台传送数据
                $.ajax({
                    url: "/4gtrafficmanager",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            // console.log(data);
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#sn_id").val(data.view.sn_id);
                            $("#user_id").val(data.view.user_id);
                            $("#device_group_id").val(data.view.device_group_id);
                            $("#iccid__").val(data.view.iccid__);
                            $("#name").val(data.view.name);


                            $('#viewRecord').find('input,select').attr("disabled", true); //disabled要在数据获取后添加，先写数据获取的方法，数据填充后VIEW操作，给所有INPUT，SELECT添加disabled
                            $('#viewRecord').modal('show'); //显示模态框
                            $(this).parents('tr').addClass('info'); //高亮选中行

                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });

            $('#viewRecord').on('hidden.bs.modal', function (e) {
                //这里要执行清除数据
                $('#viewRecord').find('input,select').attr("disabled", false); //要清除表单数据
                //添加的按钮需要清除
                $('#record-submit').remove();
                $('#record-add').remove();

                $('.data-table tr').removeClass('info'); //清除行高亮
            })
        },

        //增加
        addRecord: function () {
            $('#addRecord').on('click', function () {
                $(":input", "form[name=editForm]").not(":button", ":reset", "hidden", "submit").val("").removeAttr("checked").removeAttr("selected");
                $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-add\"><i class=\"fa fa-plus\"></i>添加</a>");
                $('#nocreate').hide();
                $('#nocreate input').attr('disabled', 'disabled');
                $('#viewRecord').modal('show');

                $('#record-add').on('click', function () {
                    //获取提交数据
                    var formdata = $("form[name=editForm]").serialize();
                    // console.log($("form[name=editForm]").serialize());

                    $.ajax({
                        url: "/admin/traffic_manager/create",
                        async: false,
                        type: "post",
                        data: formdata,
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("添加成功");
                                window.location.reload();
                            } else {
                                alert("修改失败");
                            }
                        }
                    })
                })
            });

        },
        //批量删除
        batchDel: function () {
            //全选
            $("#selectAll").on("click", function () {
                if ($(this).prop("checked")) {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", true);

                } else {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", false);
                }
            });


            //操作删除
            $('#batchDel').on('click', function () {
                var checks = $(".data-table tbody input[type='checkbox']:checked");
                if (checks.length == 0) {
                    alert("请选择要删除的账户");
                    return;
                }
                // console.log(checks.length);
                //获取要删除的id
                var idArr = [];
                for (var i = 0; i < checks.length; i++) {
                    //checks[i].parent().next();
                    idArr.push($(checks[i]).parent().next().html());
                    // console.log($(checks[i]).parent().next().html());
                }
                // console.log(idArr);
                //return;

                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除这些账户吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //正式删除数据 传递数据给控制器
                $('#confirm-del').on('click', function () {
                    $.ajax({
                        url: "/admin/traffic_manager/deleteArr",
                        async: false,
                        type: "post",
                        data: {
                            'id': idArr
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("批量删除成功");
                                window.location.reload();
                            } else {
                                alert("批量删除失败");
                            }
                        }
                    })
                })

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });

                //alert('批量删除');

            });
        },
        //搜索
        search: function () {
            JustMarvel.potting.search.searchByKeyword();
        },
        //清空搜索
        delSearch: function () {
            JustMarvel.potting.search.delSearch();
        },

        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };

    //视频管理
    JustMarvel.platform.pageVideoLibrary = {
        init: function () {
            // console.log("视频管理");
            JustMarvel.platform.pageVideoLibrary.menu();
            JustMarvel.platform.pageVideoLibrary.dataInit();
            JustMarvel.platform.pageVideoLibrary.videoPlay();
            JustMarvel.platform.pageVideoLibrary.downLoad();
            JustMarvel.platform.pageVideoLibrary.delRecord();
            JustMarvel.platform.pageVideoLibrary.queryRecord();
            JustMarvel.platform.pageVideoLibrary.search();
            JustMarvel.platform.pageVideoLibrary.goto();
        },
        menu: function () {

        },
        dataInit: function () {
            $(".record-tool li a").on('click', function () {
                $("#edit-content").fadeToggle(300, 'easeInCubic');
            });

        },

        //下载视频
        downLoad: function () {
            $('.downLoad').on('click', function () {
                var url = $(this).data('url');
                // console.log(url);
                //window.open("http://www.icm.com/static/upload/20190228/0.mp4");
                $.ajax({
                    url: "/admin/video_library/download?url=" + url,
                    async: false,
                    type: "get",
                    dataType: "json",
                    success: function (data) {
                        // console.log(data);
                        if (data.code != 200) {
                            alert("下载失败");
                            //window.location.reload();
                        }
                    }
                })
            });
        },

        //查询视频
        queryRecord: function () {
            $('.queryRecord').on('click', function () {
                var nameId = $(this).data('id');
                // console.log(viewId);
                //往后台传送数据
                $.ajax({
                    url: "/admin/video_library/fileListx?id="+nameId, //+nameId
                    async: false,
                    type: "get",
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            console.log(data);
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            var str_td = "";
                            for (var i = 0; i < data.data.list.length; i++) {
                                str_td += "<tr><td>" + data.data.list[i]['filename'] + "</td>" +
                                    "<td><a class='btn btn-success btn-sm video-play'data-imei='" + data.data.list[i]['imei'] + "' data-userdata='" + data.data.list[i]['userdata'].username+":" + data.data.list[i]['userdata'].password+"' data-userid='" + data.data.list[i]['userId'] + "' data-filename='" + data.data.list[i]['filename'] + "'><i class='fa fa-play-circle'></i>播放</a></td>" +
                                    "</tr>";
                            }
                            if (str_td == "") {
                                str_td = "<tr><td>暂无数据</td><td>暂无数据</td></tr>";
                            }
                            $("#queryRecord tbody").html(str_td);

                            $(this).parents('tr').addClass('info'); //高亮选中行

                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("查询失败");
                        }
                    }
                });
            });
        },

        //播放视频
        videoPlay: function () {
            $(document).on('click', '.video-play', function () { //$('.video-play').on('click', function () {
                //var playname = $(this).data('name');
                // console.log(playname);
                var filename = $(this).data('filename');
                var userId = $(this).data('userid');
                var userdata = $(this).data('userdata');
                var imei = $(this).data('imei');
                console.log(filename);
                // $('#userName').html(playname);

                $.ajax({
                    url: "/admin/video_library/play?filename=" + filename + "&userid=" + userId + "&imei=" + imei, //+nameId
                    async: false,
                    type: "post",
                    data: {"userdata": userdata},
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            console.log(data);
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            //$('#custom-video').empty().append("<source src=" + data.url + "  />");

                            $('#custom-video').attr('src', data.url);
                            $('#modal-video').modal('show');
                            //$(this).parents('tr').addClass('info'); //高亮选中行

                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("查询失败");
                        }
                    }
                });
            });
            $('#modal-video').on('hide.bs.modal', function () {
                $('#custom-video').get(0).pause();
                $('#custom-video').load();
                $('#custom-video').empty();

            });
        },

        //删除
        delRecord: function () {
            $('.delRecord').on('click', function () {
                $(this).parents('tr').addClass('danger');
                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除该条记录吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });
                //获取要删除的id
                var deleId = $(this).data('name');

                //确认删除
                $('#confirm-del').on('click', function () {
                    // console.log(deleId);
                    $.ajax({
                        url: "/admin/video_library/delete?id=" + deleId,
                        async: false,
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("删除成功");
                                window.location.reload();
                            } else {
                                alert("删除失败");
                            }
                        }
                    })
                    $('#warning-message').alert('close');

                });
            });
        },

        //搜索
        search: function () {
            JustMarvel.potting.search.searchByKeyword();
        },

        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };

    //车辆数据
    JustMarvel.platform.pageCarData = {
        init: function () {
            // console.log("车辆数据");
            JustMarvel.platform.pageCarData.menu();
            JustMarvel.platform.pageCarData.dataInit();
            JustMarvel.platform.pageCarData.carlocation();
            JustMarvel.platform.pageCarData.goto();

        },
        menu: function () {

        },
        dataInit: function () {
            $(".record-tool li a").on('click', function () {
                $("#edit-content").fadeToggle(300, 'easeInCubic');
            });

        },
        carlocation: function () {
            var location = [];
            var map = new AMap.Map('sub-report', {
                zoom: 4,
                resizeEnable: true,
            });
            $.ajax({
                type: "post",
                url: "/admin/car_manage/jmGPS",
                data: {
                    action: "all"
                },
                dataType: "json",
                success: function (data) {
                    var markers = [],
                        imei = [];
                    //console.log(data);
                    for (i = 0; i < data.data.length; i++) {
                        location[i] = data.data[i].device_latlng;
                        imei[i] = data.data[i].imei;

                        var markerPosition = location[i],
                            deviceimei = imei[i];

                        var marker = new AMap.Marker({
                            position: markerPosition,
                            title: "设备IMEI：" + deviceimei,
                        });

                        markers.push(marker);
                    };
                    map.plugin(["AMap.MarkerClusterer"], function () {
                        cluster = new AMap.MarkerClusterer(
                            map, // 地图实例
                            markers // 海量点组成的数组
                        );
                    });

                }
            });
        },
        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };

    //车辆事件
    JustMarvel.platform.pageCarEvent = {
        init: function () {
            // console.log("车辆事件");
            JustMarvel.platform.pageCarEvent.menu();
            JustMarvel.platform.pageCarEvent.dataInit();
            JustMarvel.platform.pageCarEvent.search();
            JustMarvel.platform.pageCarEvent.delSearch();
            JustMarvel.platform.pageCarEvent.goto();
        },
        menu: function () {

        },
        dataInit: function () {
            $(".record-tool li a").on('click', function () {
                $("#edit-content").fadeToggle(300, 'easeInCubic');
            });

        },
        //搜索
        search: function () {
            JustMarvel.potting.search.searchByKeyword();
        },
        //清空搜索
        delSearch: function () {
            JustMarvel.potting.search.delSearch();
        },
        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };

    //车辆管理
    JustMarvel.platform.pageCarManage = {
        init: function () {
            // console.log("车辆管理");
            JustMarvel.platform.pageCarManage.menu();
            JustMarvel.platform.pageCarManage.dataInit();
            JustMarvel.platform.pageCarManage.viewRecord();
            JustMarvel.platform.pageCarManage.editRecord();
            JustMarvel.platform.pageCarManage.delRecord();
            JustMarvel.platform.pageCarManage.mapRecord();
            JustMarvel.platform.pageCarManage.mapHistory();
            JustMarvel.platform.pageCarManage.search();
            JustMarvel.platform.pageCarManage.delSearch();
            JustMarvel.platform.pageCarManage.goto();


        },
        menu: function () {

        },
        dataInit: function () {
            $(".record-tool li a").on('click', function () {
                $("#edit-content").fadeToggle(300, 'easeInCubic');
            });

        },
        //地图加载
        mapRecord: function () {
            var map = {};
            // console.log(1,map);
            $('.carRecord').on('click', function () {
                $('#carRecord').modal('show'); //显示模态框
                $('#carRecord').find('input,select').attr("disabled", true); //disabled要在数据获取后添加，先写数据获取的方法，数据填充后VIEW操作，给所有INPUT，SELECT添加disabled
                var imei = $(this).data('imei'),
                    carnumber = $(this).data('');

                setTimeout(function () {
                    map = new AMap.Map('mapcontainer', {
                        zoom: 13, //级别
                        viewMode: '3D', //使用3D视图

                    });

                    $.ajax({
                        type: "post",
                        url: "/admin/car_manage/jmGPS",
                        data: {
                            action: "one",
                            imei: imei
                            // imei: "53810053836"
                        },
                        dataType: "json",
                        success: function (data) {
                            var lnglat = [];
                            var address = "暂无数据";
                            //console.log(data);

                            if (data.data.length > 0) {
                                lnglat = data.data[0].device_latlng;
                                address = data.data[0].device_address;
                                //console.log(lnglat);

                                // setTimeout(function () {
                                // 创建一个 Marker 实例：
                                var marker = new AMap.Marker({
                                    position: lnglat, // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
                                });
                                // 将创建的点标记添加到已有的地图实例：
                                map.add(marker);
                                map.setZoomAndCenter(18, lnglat);
                                // AMap.plugin('AMap.Geocoder', function () {
                                //     var geocoder = new AMap.Geocoder({
                                //         // city 指定进行编码查询的城市，支持传入城市名、adcode 和 citycode

                                //     })
                                // geocoder.getAddress(lnglat, function (status, result) {
                                //     if (status === 'complete' && result.info === 'OK') {
                                //         // result为对应的地理位置详细信息
                                //         var address = result.regeocode.formattedAddress;
                                //         // console.log(address);
                                //         $('#warningpoint').val(address);

                                //     }
                                // })
                                // });
                                // }, 300);
                            }
                            $('#warningpoint').val(address);
                        }

                    });
                }, 500);

                $('#carRecord').on('hide.bs.modal', function () {

                    map.destroy();
                    $('#carRecord').off('hide.bs.modal');
                });
            });

        },
        //设备轨迹
        mapHistory: function () {
            var map = {},
                imei = '';
            $('#carhistorysearch').on('click', function () {
                var flag = true;
                var startDate = $('#carHistorystartDate').val();
                var endDate = $('#carHistoryendDate').val();
                if (startDate == "" || endDate == "") {
                    alert("请选择时间区间");
                    return;
                }

                $.ajax({
                    type: "post",
                    url: "/admin/car_manage/orbit",
                    async: false,
                    data: {
                        imei: imei,
                        // imei: "53810054022",
                        begin_time: startDate,
                        end_time: endDate,
                    },
                    dataType: "json",
                    success: function (data) {
                        // console.log(data);

                        var historylnglat = [];
                        for (i = 0; i < data.data.length; i++) {
                            historylnglat.push(data.data[i].device_latlng);
                        };

                        // console.log(historylnglat);
                        var startIcon = new AMap.Icon({
                            // 图标尺寸
                            size: new AMap.Size(25, 34),
                            // 图标的取图地址
                            image: 'assets/images/amap/dir-marker.png',
                            // 图标所用图片大小
                            imageSize: new AMap.Size(135, 40),
                            // 图标取图偏移量
                            imageOffset: new AMap.Pixel(-9, -3)
                        });
                        var endIcon = new AMap.Icon({
                            size: new AMap.Size(25, 34),
                            image: 'assets/images/amap/dir-marker.png',
                            imageSize: new AMap.Size(135, 40),
                            imageOffset: new AMap.Pixel(-95, -3)
                        });
                        var k = 0,
                            startMarker = {},
                            endMarker = {};
                        k = historylnglat.length - 1;
                        if (historylnglat.length > 0) { //判断是否有数据返回
                            // 创建一个 Icon
                            if (historylnglat.length > 1) {
                                // 创建一个 Marker 实例：
                                startMarker = new AMap.Marker({
                                    position: new AMap.LngLat(historylnglat[0][0], historylnglat[0][1]), // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
                                    //position: new Amap(117.99268261858, 36.820054707856),
                                    icon: startIcon,
                                    offset: new AMap.Pixel(-13, -30)
                                });
                                endMarker = new AMap.Marker({
                                    position: new AMap.LngLat(historylnglat[k][0], historylnglat[k][1]),
                                    //position: data.data[10].device_latlng,
                                    icon: endIcon,
                                    offset: new AMap.Pixel(-13, -30)
                                });
                                // console.log(startMarker, endMarker);
                            } else {
                                // 创建一个 Marker 实例：
                                startMarker = new AMap.Marker({
                                    position: historylnglat[0], // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
                                });
                                endMarker = new AMap.Marker({
                                    position: historylnglat[k],
                                });
                            };


                            var polyline = new AMap.Polyline({
                                path: historylnglat,
                                isOutline: true,
                                outlineColor: '#ffeeff',
                                borderWeight: 3,
                                strokeColor: "#3366FF",
                                strokeOpacity: 1,
                                strokeWeight: 6,
                                // 折线样式还支持 'dashed'
                                strokeStyle: "solid",
                                // strokeStyle是dashed时有效
                                strokeDasharray: [10, 5],
                                lineJoin: 'round',
                                lineCap: 'round',
                                zIndex: 50,
                            });
                            // 将创建的点标记添加到已有的地图实例：
                            // console.log(startMarker, endMarker, polyline);
                            map.add([startMarker, endMarker, polyline]);
                            // console.log(map);

                            map.setFitView();

                        } else {
                            alert("未查询到相关信息！请重新选择！！");
                        };
                    }
                });
            });
            $('.carHistory').on('click', function () {
                $('#carHistory').modal('show'); //显示模态框
                $('#devicenumber-carHistory').attr("disabled", true); //disabled要在数据获取后添加，先写数据获取的方法，数据填充后VIEW操作，给所有INPUT，SELECT添加disabled
                $('devicenumber').removeAttr("disabled");
                $('#carHistorystartDate,#carHistoryendDate').datetimepicker(Object.assign(JustMarvel.potting.datetimepicker.options, {
                    format: 'yyyy-mm-dd hh:ii',
                    minView: 0,
                    minuteStep: 5,
                })).on('hide.bs.modal', function (event) {
                    // prevent datepicker from firing bootstrap modal "show.bs.modal"
                    event.stopPropagation();
                });

                imei = $(this).data('imei');
                $('#devicenumber-carHistory').val(imei);

                setTimeout(function () {
                    map = new AMap.Map('mapHistorycontainer', {
                        zoom: 13, //级别
                        viewMode: '3D', //使用3D视图
                    });

                    $('#carHistory').on('hide.bs.modal', function () {
                        map.destroy();
                    });
                }, 300);
            });
        },
        //查看
        viewRecord: function () {
            $('.viewRecord').on('click', function () {
                var viewId = $(this).data('name');
                // console.log(viewId);
                //往后台传送数据
                $.ajax({
                    url: "/carmanage",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            // console.log(data);
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#plate_number").val(data.view.plate_number);
                            $("#car_brand").val(data.view.car_brand);
                            $("#car_model").val(data.view.car_model);
                            $("#user_id").val(data.view.user_id);
                            $("#device_id").val(data.view.device_id);


                            $('#viewRecord').find('input,select').attr("disabled", true); //disabled要在数据获取后添加，先写数据获取的方法，数据填充后VIEW操作，给所有INPUT，SELECT添加disabled
                            $('#viewRecord').modal('show'); //显示模态框
                            $(this).parents('tr').addClass('info'); //高亮选中行

                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });

            $('#viewRecord').on('hidden.bs.modal', function (e) {
                //这里要执行清除数据
                $('#viewRecord').find('input,select').attr("disabled", false); //要清除表单数据
                //添加的按钮需要清除
                $('#record-submit').remove();
                $('#record-add').remove();

                $('.data-table tr').removeClass('info'); //清除行高亮
            })
        },
        //编辑
        editRecord: function () {
            $('.editRecord').on('click', function () {
                var viewId = $(this).data('name');
                // console.log(viewId);
                //从接口查询数据
                $.ajax({
                    url: "/carmanage",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#plate_number").val(data.view.plate_number);
                            $("#car_brand").val(data.view.car_brand);
                            $("#car_model").val(data.view.car_model);
                            $("#user_id").val(data.view.user_id);
                            $("#device_id").val(data.view.device_id);

                            $(this).parents('tr').addClass('warning');
                            //这里先通过接口获取数据，获取数据后，添加编辑按钮
                            $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-submit\"><i class=\"fa fa-save\"></i>保存</a>");
                            $('#viewRecord').modal('show');

                            //添加的提交按钮，绑定提交事件
                            $('#record-submit').on('click', function () {
                                // console.log($("#accountname").val());
                                var formdata = $("form[name=editForm]").serialize();
                                // console.log($("form[name=editForm]").serialize());

                                $.ajax({
                                    url: "/admin/car_manage/edit?id=" + viewId,
                                    async: false,
                                    type: "post",
                                    data: formdata,
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.code == 200) {
                                            alert("修改成功");
                                            window.location.reload();
                                        } else {
                                            alert("修改失败");
                                        }
                                    }
                                })

                            });
                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });
            //模态框隐藏后事件
            $('#viewRecord').on('hidden.bs.modal', function () {
                $('#record-submit').remove();
                $('#record-add').remove();
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });

        },
        //删除
        delRecord: function () {
            $('.delRecord').on('click', function () {
                $(this).parents('tr').addClass('danger');
                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除该条记录吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });
                //获取要删除的id
                var deleId = $(this).data('name');

                //确认删除
                $('#confirm-del').on('click', function () {
                    // console.log(deleId);
                    $.ajax({
                        url: "/admin/car_manage/delete?id=" + deleId,
                        async: false,
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("删除成功");
                                window.location.reload();
                            } else {
                                alert("删除失败");
                            }
                        }
                    })
                    $('#warning-message').alert('close');

                });
            });
        },
        //搜索
        search: function () {
            JustMarvel.potting.search.searchByKeyword();
        },
        //清空搜索
        delSearch: function () {
            JustMarvel.potting.search.delSearch();
        },
        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };

    //任务管理
    JustMarvel.platform.pageTask = {
        init: function () {
            // console.log("任务管理");
            JustMarvel.platform.pageTask.menu();
            JustMarvel.platform.pageTask.dataInit();
            JustMarvel.platform.pageTask.viewRecord();
            JustMarvel.platform.pageTask.editRecord();
            JustMarvel.platform.pageTask.delRecord();
            JustMarvel.platform.pageTask.addRecord();
            JustMarvel.platform.pageTask.batchDel();
            JustMarvel.platform.pageTask.search();
            JustMarvel.platform.pageTask.delSearch();
            JustMarvel.platform.pageTask.goto();
            JustMarvel.platform.pageTask.lowerRecord();
            JustMarvel.platform.pageTask.pushRecord();
            JustMarvel.platform.pageTask.taskSwitch();
        },
        menu: function () {

        },

        //数据初始化
        dataInit: function () {
            //$(".record-tool li a").on('click', function () {
            //    $("#edit-content").fadeToggle(300, 'easeInCubic');
            //});

        },
        //查看
        viewRecord: function () {
            $('.viewRecord').on('click', function () {
                //alert(111);
                var viewId = $(this).data('name');
                // console.log(viewId);
                //往后台传送数据
                $.ajax({
                    url: "/task",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            console.log(data);
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#name").val(data.view.name);
                            $("#task_type_id").val(data.view.task_type_id);
                            $("#illustration").val(data.view.illustration);
                            $("#begin_at").val(data.view.begin_at);
                            $("#end_at").val(data.view.end_at);
                            $("#reward").val(data.view.reward);
                            $("#partake_limit").val(data.view.partake_limit);
                            $("#content").val(data.view.content);

                            /*if (data.view.status == 1) {
                                $(".status.s1").attr("checked", 'checked');
                            } else {
                                $(".status.s0").attr("checked", 'checked');
                            }*/

                            $('#viewRecord').find('input,select,textarea').attr("disabled", true); //disabled要在数据获取后添加，先写数据获取的方法，数据填充后VIEW操作，给所有INPUT，SELECT添加disabled
                            $('#viewRecord').modal('show'); //显示模态框
                            $(this).parents('tr').addClass('info'); //高亮选中行

                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });

            $('#viewRecord').on('hidden.bs.modal', function (e) {
                //这里要执行清除数据
                $('#viewRecord').find('input,select,textarea').attr("disabled", false); //要清除表单数据
                //添加的按钮需要清除
                $('#record-submit').remove();
                $('#record-add').remove();

                $('.data-table tr').removeClass('info'); //清除行高亮
            })
        },
        //删除
        delRecord: function () {
            $('.delRecord').on('click', function () {
                $(this).parents('tr').addClass('danger');
                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除该条记录吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });
                //获取要删除的id
                var deleId = $(this).data('name');

                //确认删除
                $('#confirm-del').on('click', function () {
                    // console.log(deleId);
                    $.ajax({
                        url: "/admin/task/delete?id=" + deleId,
                        async: false,
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("删除成功");
                                window.location.reload();
                            } else {
                                alert("删除失败");
                            }
                        }
                    })
                    $('#warning-message').alert('close');

                });
            });
        },
        //增加
        addRecord: function () {
            $('#addRecord').on('click', function () {
                $(":input", "form[name=editForm]").not(":button", ":reset", "hidden", "submit").val("").removeAttr("checked").removeAttr("selected");
                $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-add\"><i class=\"fa fa-plus\"></i>添加</a>");
                $('#nocreate').hide();
                $('#nocreate input').attr('disabled', 'disabled');
                $('#viewRecord').modal('show');

                $('#record-add').on('click', function () {
                    //获取提交数据
                    var name = $("#name").val();
                    ///console.log(name);return;
                    if(name.length==0){
                        alert("任务名称不能为空");
                        return;
                    }
                    var partake_limit = $("#partake_limit").val();
                    //日期函数使用
                    var begin_at = (new Date($("#begin_at").val())).getTime();
                    var end_at = (new Date($("#end_at").val())).getTime();
                    //判断时间大小
                    if(!(begin_at < end_at)){
                        alert("开始时间必须早于结束时间");
                        return;
                    }
                    //判断是否为正整数
                    if(!(/(^[0-9]\d*$)/.test(partake_limit))){
                        alert("限制人数请输入正整数");
                        return;
                    }

                    var formdata = $("form[name=editForm]").serialize();
                    //console.log($("form[name=editForm]").serialize());return;
                    $.ajax({
                        url: "/admin/task/create",
                        async: false,
                        type: "post",
                        data: formdata,
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                // console.log("添加成功");
                                window.location.reload();
                            } else {
                                alert("修改失败");
                            }
                        }
                    })
                })
            });

        },
        //编辑
        editRecord: function () {
            $('.editRecord').on('click', function () {
                var viewId = $(this).data('name');
                // console.log(viewId);
                //从接口查询数据
                $.ajax({
                    url: "/task",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            /*console.log(data);
                            return;*/
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#name").val(data.view.name);
                            $("#task_type_id").val(data.view.task_type_id);
                            $("#illustration").val(data.view.illustration);
                            $("#begin_at").val(data.view.begin_at);
                            $("#end_at").val(data.view.end_at);
                            $("#reward").val(data.view.reward);
                            $("#partake_limit").val(data.view.partake_limit);
                            $("#content").val(data.view.content);

                            /* if (data.view.status == 1) {
                                 $(".status.s1").attr("checked", 'checked');
                             } else {
                                 $(".status.s0").attr("checked", 'checked');
                             }*/

                            $(this).parents('tr').addClass('warning');
                            //这里先通过接口获取数据，获取数据后，添加编辑按钮
                            $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-submit\"><i class=\"fa fa-save\"></i>保存</a>");
                            $('#viewRecord').modal('show');

                            //添加的提交按钮，绑定提交事件
                            $('#record-submit').on('click', function () {
                                //获取提交数据
                                var partake_limit = $("#partake_limit").val();
                                //日期函数使用
                                var begin_at = (new Date($("#begin_at").val())).getTime();
                                var end_at = (new Date($("#end_at").val())).getTime();
                                //判断时间大小
                                if(!(begin_at<end_at)){
                                    alert("开始时间必须早于结束时间");
                                    return;
                                }
                                //判断是否为正整数
                                if(!(/(^[0-9]\d*$)/.test(partake_limit))){
                                    alert("限制人数请输入正整数");
                                    return;
                                }
                                var formdata = $("form[name=editForm]").serialize();

                                $.ajax({
                                    url: "/admin/task/edit?id=" + viewId,
                                    async: false,
                                    type: "post",
                                    data: formdata,
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.code == 200) {
                                            // console.log("修改成功");
                                            window.location.reload();
                                        } else {
                                            alert("修改失败");
                                        }
                                    }
                                })

                            });
                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });
            //模态框隐藏后事件
            $('#viewRecord').on('hidden.bs.modal', function () {
                $('#record-submit').remove();
                $('#record-add').remove();
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });

        },
        //批量删除
        batchDel: function () {
            //全选
            $("#selectAll").on("click", function () {
                if ($(this).prop("checked")) {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", true);

                } else {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", false);
                }
            });


            //操作删除
            $('#batchDel').on('click', function () {
                var checks = $(".data-table tbody input[type='checkbox']:checked");
                if (checks.length == 0) {
                    alert("请选择要删除的账户");
                    return;
                }
                // console.log(checks.length);
                //获取要删除的id
                var idArr = [];
                for (var i = 0; i < checks.length; i++) {
                    //checks[i].parent().next();
                    idArr.push($(checks[i]).parent().next().html());
                    // console.log($(checks[i]).parent().next().html());
                }
                // console.log(idArr);
                //return;

                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除这些账户吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //正式删除数据 传递数据给控制器
                $('#confirm-del').on('click', function () {
                    $.ajax({
                        url: "/admin/task/deleteArr",
                        async: false,
                        type: "post",
                        data: {
                            'id': idArr
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("批量删除成功");
                                window.location.reload();
                            } else {
                                alert("批量删除失败");
                            }
                        }
                    })
                })

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });

                //alert('批量删除');

            });
        },
        //搜索
        search: function () {
            JustMarvel.potting.search.searchByKeyword();
        },
        //清空搜索
        delSearch: function () {
            JustMarvel.potting.search.delSearch();
        },
        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        },
        //下发任务
        lowerRecord: function () {
            $('.lowerRecord').on('click', function () {
                var viewId = $(this).data('name');
                // console.log(viewId);
                $('#lowerRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-add\"><i class=\"fa fa-plus\"></i>执行</a>");
                $('#lowerRecord').modal('show');
                $('#lower_at1').removeAttr("disabled");
                $('.lower_status').on('click', function () {
                    var status = $(this).val();
                     console.log(status);
                    if (status == 1) {
                        $(".lower_status.l1").attr("checked", 'checked');
                        $(".form-group.region_id").css('display', 'block');
                        $(".form-group.device_group_id").css('display', 'block');
                        $(".form-group.user").css('display', 'block');
                        $(".form-group.lower_at").css('display', 'none');
                        $('#lower_at').attr('disabled', 'disabled');

                    } else if (status == 0) {
                        $(".lower_status.l0").attr("checked", 'checked');
                        $(".form-group.lower_at").css('display', 'block');
                        $(".form-group.region_id").css('display', 'block');
                        $(".form-group.device_group_id").css('display', 'block');
                        $(".form-group.user").css('display', 'block');
                    }


                    //选择用户组
                    $('.user').on('click', function () {
                        var user = $(this).val();
                        if (user == 1) {
                            $('#user_group_id').css('display', 'block');
                            $('#user_id').css('display', 'none');
                        } else if (user == 2) {
                            $('#user_group_id').css('display', 'none');
                            $('#user_id').css('display', 'block');
                        }
                    })
                });

                $('#record-add').on('click', function () {
                    //console.log(status);return;
                    if($("#device_group_id").val()==0){
                        alert("请选择设备组，再提交");return;
                    }
                    var user = $("input[name=user]:checked").val();
                    //alert(user);
                    //return;
                    if(user == 1){
                        console.log($("#user_group_id").val());
                        if($("#user_group_id").val()==0){
                            alert("请选择用户组，再提交");return;
                        }
                    }else if(user == 2){
                        if($("#user_id").val()==0){
                            alert("请选择用户，再提交");return;
                        }
                    }
                    $('#lowerRecord').modal('hide');
                    //添加警告
                    $body.append("<div id=\"warning-message\" class=\"alert alert-info alert-dismissible fade in\" role=\"alert\">" +
                        "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                        "<h4 class=\"text-center\">确认要推送吗</h4>" +
                        "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-info\">确认</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                        "</div>"
                    );
                    $('#warning-message').show();
                    //正式删除数据 传递数据给控制器
                    $('#confirm-del').on('click', function () {
                        //获取提交数据
                        var formdata = $("form[name=lowerForm]").serialize();
                        //console.log($("form[name=lowerForm]").serialize());
                        $.ajax({
                            url: "/admin/task/lower?id=" + viewId,
                            async: false,
                            type: "post",
                            data: formdata,
                            dataType: "json",
                            success: function (data) {
                                if (data.code == 200) {
                                    // console.log("下发成功");
                                    window.location.reload();
                                } else {
                                    alert("下发失败");
                                }
                            }
                        })
                    })
                    // return;
                    //手动关闭警告框
                    $('#warning-message .cancle').on('click', function () {
                        $('#warning-message').alert('close');
                    });

                    //警告框移除后事件
                    $('#warning-message').on('closed.bs.alert', function () {
                        $('.data-table tr').removeClass('danger'); //清除行高亮
                    });

                });
            });
            //模态框隐藏后事件
            $('#lowerRecord').on('hidden.bs.modal', function () {
                $('#record-submit').remove();
                $('#record-add').remove();
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });
        },
        //推送任务
        pushRecord: function () {
            $('.pushRecord').on('click', function () {
                $(this).parents('tr').addClass('info');
                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-info alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要推送这条记录吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-info\">确认</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();
                //获取要推送的id
                var pushId = $(this).data('name');

                //确认删除
                $('#confirm-del').on('click', function () {
                    // console.log(deleId);
                    $.ajax({
                        url: "/admin/task/jpush?id=" + pushId,
                        async: false,
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("推送成功");
                                window.location.reload();
                            } else {
                                alert("推送失败");
                            }
                        }
                    })
                    $('#warning-message').alert('close');

                });
                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('info'); //清除行高亮
                });
            });
        },
        //任务开关
        taskSwitch: function () {
            //添加警告
            $body.append("<div id=\"warning-message\" class=\"alert alert-warning alert-dismissible fade in\" role=\"alert\">" +
                "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                "<h4 class=\"text-center\">确认要开启/关闭这项任务吗？</h4>" +
                "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-warning\">确认</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                "</div>"
            );

            var taskId = "";
            var status  = "";
            var closed_at  = "";

            // console.log($('.taskswitch').length);
            $('.taskswitch').bootstrapSwitch({
                onSwitchChange: function (event, state) {
                    $(this).parents('tr').addClass('warning');
                    var myDate = new Date();
                    //获取当前年
                    var year = myDate.getFullYear();
                    //获取当前月
                    var month = myDate.getMonth() + 1;
                    //获取当前日
                    var date = myDate.getDate();
                    var h = myDate.getHours(); //获取当前小时数(0-23)
                    var m = myDate.getMinutes(); //获取当前分钟数(0-59)
                    var s = myDate.getSeconds();
                    // 获取当前时间
                    function getNow(s) {
                        return s < 10 ? '0' + s : s;
                    }

                    // 获取当前时间
                    closed_at = year + '-' + getNow(month) + "-" + getNow(date) + " " + getNow(h) + ':' + getNow(m) + ":" + getNow(s);

                    var end_at = new Date($(this).data("end_at")).getTime();
                    var nowtime= myDate.getTime();
                    var difference = (end_at-nowtime);

                    console.log(end_at);
                    console.log(nowtime);
                    console.log(difference);//return;

                    //判断时间是否结束不能开启
                    if(difference<0){
                        alert("任务已结束，无法开启");
                        //$(this).bootstrapSwitch('toggleState');
                        $(this).bootstrapSwitch('state',false,true);
                        return;
                        //die();
                    }
                    taskId = $(this).data('taskid');
                    if (state == false) {
                        status = 1;
                    } else {
                        status = 0;
                    }
                    $('#warning-message').show();
                }
            });

            //确认删除
            $('#confirm-del').on('click', function () {
                //传递数据给控制器
                $.ajax({
                    url: "/admin/task/close?id=" + taskId,
                    async: false,
                    type: "post",
                    data: {
                        "status": status,
                        "closed_at": closed_at
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.code == 200) {
                            // console.log("成功");
                            window.location.reload();
                        } else {
                            alert("失败");
                        }
                    }
                })
            });

            //手动关闭警告框
            $('#warning-message .cancle').on('click', function () {
                $('#warning-message').alert('close');
                $(".data-table tr.warning .taskswitch").bootstrapSwitch('toggleState');
                if(status==1){
                    $(".data-table tr.warning .taskswitch").bootstrapSwitch('state',false,true);
                }else if(status==0){
                    $(".data-table tr.warning .taskswitch").bootstrapSwitch('state',true,true);
                }

            });
            //警告框移除后事件
            $('#warning-message').on('closed.bs.alert', function () {
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });
        }

    };

    //接单管理
    JustMarvel.platform.pageReceipt = {
        init: function () {
            // console.log("接单管理");
            JustMarvel.platform.pageReceipt.menu();
            JustMarvel.platform.pageReceipt.dataInit();
            JustMarvel.platform.pageReceipt.viewRecord();
            JustMarvel.platform.pageReceipt.editRecord();
            JustMarvel.platform.pageReceipt.delRecord();
            JustMarvel.platform.pageReceipt.examineRecord();
            JustMarvel.platform.pageReceipt.videoPlay();
            //JustMarvel.platform.pageReceipt.addRecord();
            //JustMarvel.platform.pageReceipt.batchDel();
            JustMarvel.platform.pageReceipt.search();
            JustMarvel.platform.pageReceipt.search();
            JustMarvel.platform.pageReceipt.delSearch();
            JustMarvel.platform.pageReceipt.goto();
        },
        menu: function () {

        },
        //数据初始化
        dataInit: function () {
            //$(".record-tool li a").on('click', function () {
            //    $("#edit-content").fadeToggle(300, 'easeInCubic');
            //});
        },
        //验证
        examineRecord: function () {
            $('.examineRecord').on('click', function () {
                var taskId = $(this).data('task');
                var userId = $(this).data('user');
                // console.log(taskId);
                // console.log(userId);
                $('#examineRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-add\"><i class=\"fa fa-plus\"></i>执行</a>");
                $('#examineRecord').modal('show');
                $('.status').on('click', function () {
                    var status = $(this).val();
                    // console.log(status);
                    if (status == 4) {
                        $(".status.s1").attr("checked", 'checked');
                        $(".form-group.conclusion").css('display', 'none');
                        // $('#conclusion').attr('disabled', 'disabled');

                    } else if (status == 3) {
                        $(".status.s0").attr("checked", 'checked');
                        $(".form-group.conclusion").css('display', 'block');
                        //$('#conclusion').attr('disabled', '');
                    }
                });


                $('#record-add').on('click', function () {
                    //获取提交数据
                    var formdata = $("form[name=examineForm]").serialize();
                    // console.log($("form[name=examineForm]").serialize());

                    $.ajax({
                        url: "/admin/receipt/examine?taskid=" + taskId + "&userid=" + userId,
                        async: false,
                        type: "post",
                        data: formdata,
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                // console.log("审核成功");
                                window.location.reload();
                            } else {
                                alert("审核失败");
                            }
                        }
                    })
                })
            });
            //模态框隐藏后事件
            $('#examineRecord').on('hidden.bs.modal', function () {
                $('#record-submit').remove();
                $('#record-add').remove();
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });
        },
        //查看
        viewRecord: function () {
            $('.viewRecord').on('click', function () {
                var $body = $('body');
                //获取浏览器页面可见高度和宽度
                var _PageHeight = document.documentElement.clientHeight,
                    _PageWidth = document.documentElement.clientWidth;
                //计算loading框距离顶部和左部的距离（loading框的宽度为215px，高度为61px）
                var _LoadingTop = _PageHeight > 61 ? (_PageHeight - 61) / 2 : 0,
                    _LoadingLeft = _PageWidth > 215 ? (_PageWidth - 215) / 2 : 0;
                //在页面未加载完毕之前显示的loading Html自定义内容
                var _LoadingHtml = '<div id="loadingDiv" style="position:absolute;left:0;width:100%;height:' + _PageHeight + 'px;top:0;background:#f3f8ff;opacity:0.5;filter:alpha(opacity=80);z-index:10000;"><div style="position: absolute; cursor1: wait; left: ' + _LoadingLeft + 'px; top:' + _LoadingTop + 'px; width: auto; height: 57px; line-height: 57px; padding-left: 50px; padding-right: 5px; background: #fff url(assets/images/logo/loading.gif) no-repeat scroll 5px 10px; border: 2px solid #95B8E7; color: #696969; font-family:\'Microsoft YaHei\';">页面加载中，请等待...</div></div>';
                //呈现loading效果
                if($('#loadingDiv').length<=0){
                    $body.append(_LoadingHtml);
                }
                //$body.append(_LoadingHtml);
                $('#loadingDiv').show();

                var taskId = $(this).data('task');
                var userId = $(this).data('user');
                // console.log(viewId);
                //从接口查询数据
                $.ajax({
                    url: "/admin/receipt/view?taskid="+taskId+"&userid="+userId,
                    async: true,
                    type: "post",
                    dataType: "json",
                    success: function (data) {
                        // console.log(data);
                        if (data.code == 200) {
                            //监听加载状态改变
                            $('#loadingDiv').hide();
                            //绑定后台传送来的数据
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            var str_td = "";
                            for (var i = 0; i < data.data.list.length; i++) {
                                str_td += "<tr><td>" + data.data.list[i]['title'] + "</td>" +
                                    "<td><a class='btn btn-success btn-sm' target='_blank' href='" + data.data.list[i]['server_url'] +"'>查看</a></td>" +
                                    "</tr>";
                            }
                            if (str_td == "") {
                                str_td = "<tr><td>暂无数据</td><td>暂无数据</td></tr>";
                            }
                            $("#viewRecord tbody").html(str_td);
                            $(this).parents('tr').addClass('info'); //高亮选中行

                            $('#viewRecord').modal('show'); //显示模态框
                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("查询数据失败");
                        }
                    }
                });
            });
            //模态框隐藏后事件
            $('#viewRecord').on('hidden.bs.modal', function () {
                $('#record-submit').remove();
                $('#record-add').remove();
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });

        },

        //播放视频
        videoPlay: function () {
            /*$(document).on('click', '.video-play', function () { //$('.video-play').on('click', function () {
                var url = $(this).data('url');
                $('#custom-video').attr('src',url);
                $('#modal-video').modal('show');
            });
            $('#modal-video').on('hide.bs.modal', function () {
                $('#custom-video').get(0).pause();
                $('#custom-video').load();
                $('#custom-video').empty();
            });*/
        },
        //编辑
        editRecord: function () {
            $('.editRecord').on('click', function () {
                var taskId = $(this).data('task');
                var userId = $(this).data('user');
                // console.log(viewId);
                //从接口查询数据
                $.ajax({
                    url: "/receipt",
                    async: false,
                    type: "post",
                    data: {
                        'taskId': taskId,
                        'userId': userId,
                    },
                    dataType: "json",
                    success: function (data) {
                        // console.log(data);
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.task_id);
                            $("#conclusion").html(data.view.conclusion);
                            $("#receive_at").val(data.view.receive_at);
                            $("#submit_at").val(data.view.submit_at);
                            $("#reward").val(data.view.reward);
                            $("#content").html(data.view.content);

                            /*if (data.view.status == 1) {
                                $(".status.s1").attr("checked", 'checked');
                            } else if(data.view.status == 0) {
                                $(".status.s0").attr("checked", 'checked');
                            }*/

                            $(this).parents('tr').addClass('warning');
                            //这里先通过接口获取数据，获取数据后，添加编辑按钮
                            $('#editRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-submit\"><i class=\"fa fa-save\"></i>保存</a>");
                            $('#editRecord').modal('show');

                            //添加的提交按钮，绑定提交事件
                            $('#record-submit').on('click', function () {
                                var formdata = $("form[name=editForm]").serialize();
                                // console.log($("form[name=editForm]").serialize());

                                $.ajax({
                                    url: "/admin/receipt/edit?taskid=" + taskId + "&userid=" + userId,
                                    async: false,
                                    type: "post",
                                    data: formdata,
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.code == 200) {
                                            // console.log("修改成功");
                                            window.location.reload();
                                        } else {
                                            alert("修改失败");
                                        }
                                    }
                                })
                            });
                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });
            //模态框隐藏后事件
            $('#editRecord').on('hidden.bs.modal', function () {
                $('#record-submit').remove();
                $('#record-add').remove();
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });

        },
        //删除
        delRecord: function () {
            $('.delRecord').on('click', function () {
                $(this).parents('tr').addClass('danger');
                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除该条记录吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });
                //获取要删除的id
                var taskId = $(this).data('task');
                var userId = $(this).data('user');

                //确认删除
                $('#confirm-del').on('click', function () {
                    // console.log(deleId);
                    $.ajax({
                        url: "/admin/receipt/delete?taskid=" + taskId + "&userid=" + userId,
                        async: false,
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("删除成功");
                                window.location.reload();
                            } else {
                                alert("删除失败");
                            }
                        }
                    })
                    $('#warning-message').alert('close');

                });
            });
        },
        //搜索
        search: function () {
            JustMarvel.potting.search.searchByKeyword();
        },
        //清空搜索
        delSearch: function () {
            JustMarvel.potting.search.delSearch();
        },

        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };

    //SN管理
    JustMarvel.platform.pageSN = {
        init: function () {
            // console.log("SN管理");
            JustMarvel.platform.pageSN.menu();
            // JustMarvel.platform.pageSN.view();
            JustMarvel.platform.pageSN.dataInit();
            //stMarvel.platform.pageAdmin.viewRecord();
            JustMarvel.platform.pageSN.handleRecord();
            JustMarvel.platform.pageSN.editRecord();
            //JustMarvel.platform.pageSN.delRecord();
            JustMarvel.platform.pageSN.addRecord();
            JustMarvel.platform.pageSN.batchHandle();
            JustMarvel.platform.pageSN.batchAdd();
            JustMarvel.platform.pageSN.batchType();
            JustMarvel.platform.pageSN.search();
            JustMarvel.platform.pageSN.delSearch();
            JustMarvel.platform.pageSN.goto();
        },
        menu: function () {

        },

        //数据初始化
        dataInit: function () {
            //全选
            $("#selectAll").on("click", function () {
                if ($(this).prop("checked")) {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", true);

                } else {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", false);
                }
            });
            //$(".record-tool li a").on('click', function () {
            //    $("#edit-content").fadeToggle(300, 'easeInCubic');
            //});
        },
        //分配
        handleRecord: function () {
            $('.handleRecord').on('click', function () {
                alert("分配");

            });
        },

        //批量分配
        batchHandle: function () {
            $('#batchHandle').on('click', function () {
                alert("批量分配");

            });
        },

        //批量导入
        batchAdd: function () {
            //操作导入
            $('.batchAdd').on('click', function () {
                //这里先通过接口获取数据，获取数据后，添加编辑按钮
                $('#batchAdd .modal-footer').append("<a class=\"btn btn-success\" id=\"record-submit\"><i class=\"fa fa-save\"></i>保存</a>");
                $('#batchAdd').modal('show');
                //添加的提交按钮，绑定提交事件
                $('#record-submit').on('click', function () {
                    var file_obj = document.getElementById('fileUp').files[0];
                    // console.log(file_obj);return;
                    var fd = new FormData();
                    //fd.append('username', 'root');
                    fd.append('fileUp', file_obj);
                    $.ajax({
                        url: "/admin/sn/importCsv",
                        type: "post",
                        data: fd,
                        processData: false, //tell jQuery not to process the data
                        contentType: false, //tell jQuery not to set contentType
                        success: function (data) {
                            if (data.code == 200) {
                                alert("导入成功");
                                window.location.reload();
                            } else {
                                alert("导入失败");
                            }
                        }
                    })
                });
            });
            //模态框隐藏后事件
            $('#batchAdd').on('hidden.bs.modal', function () {
                $('#record-submit').remove();
                $('#record-add').remove();
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });
        },

        //增加类型
        batchType: function () {
            $('#batchType').on('click', function () {
                alert("增加类型");

            });
        },

        //删除
        /* delRecord: function () {
             $('.delRecord').on('click', function () {
                 $(this).parents('tr').addClass('danger');
                 //添加警告
                 $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                     "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                     "<h4 class=\"text-center\">确认要删除该条记录吗？</h4>" +
                     "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                     "</div>"
                 );
                 $('#warning-message').show();

                 //手动关闭警告框
                 $('#warning-message .cancle').on('click', function () {
                     $('#warning-message').alert('close');
                 });

                 //警告框移除后事件
                 $('#warning-message').on('closed.bs.alert', function () {
                     $('.data-table tr').removeClass('danger'); //清除行高亮
                 });
                 //获取要删除的id
                 var deleId = $(this).data('name');

                 //确认删除
                 $('#confirm-del').on('click', function () {
                     // console.log(deleId);
                     $.ajax({
                         url:"/admin/sn/delete?id="+deleId,
                         async:false,
                         type:"get",
                         dataType:"json",
                         success:function(data){
                             if(data.code ==200){
                                 alert("删除成功");
                                 window.location.reload();
                             }else{
                                 alert("删除失败");
                             }
                         }
                     })
                     $('#warning-message').alert('close');

                 });
             });
         },*/

        //编辑
        editRecord: function () {
            $('.editRecord').on('click', function () {
                /*$('#nocreate').hide();
                $('#nocreate input').attr('disabled','disabled');*/
                var viewId = $(this).data('name');
                // console.log(viewId);
                //从接口查询数据
                $.ajax({
                    url: "/sn",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#sn").val(data.view.sn);
                            $("#imei").val(data.view.imei);
                            if (data.view.status == 1) {
                                $(".status.s1").attr("checked", 'checked');
                            } else {
                                $(".status.s0").attr("checked", 'checked');
                            }
                            // $("input[name=status]").val(data.view.status);
                            $("#device_model_id").val(data.view.device_model_id);
                            $("#franchiser_group_id").val(data.view.franchiser_group_id);

                            $(this).parents('tr').addClass('warning');
                            //这里先通过接口获取数据，获取数据后，添加编辑按钮
                            $('#editRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-submit\"><i class=\"fa fa-save\"></i>保存</a>");
                            $('#editRecord').modal('show');

                            //添加的提交按钮，绑定提交事件
                            $('#record-submit').on('click', function () {
                                // console.log($("#accountname").val());
                                var formdata = $("form[name=editForm]").serialize();
                                // console.log($("form[name=editForm]").serialize());

                                $.ajax({
                                    url: "/admin/sn/edit?id=" + viewId,
                                    async: false,
                                    type: "post",
                                    data: formdata,
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.code == 200) {
                                            alert("修改成功");
                                            window.location.reload();
                                        } else {
                                            alert("修改失败");
                                        }
                                    }
                                })

                            });
                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });
            //模态框隐藏后事件
            $('#editRecord').on('hidden.bs.modal', function () {
                $('#record-submit').remove();
                $('#record-add').remove();
                //$('#nocreate').show();
                //$('#nocreate input').removeAttr('disabled','disabled');
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });

        },

        //增加
        addRecord: function () {
            $('#addRecord').on('click', function () {
                $(":input", "form[name=editForm]").not(":button", ":reset", "hidden", "submit").val("").removeAttr("checked").removeAttr("selected");
                $('#editRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-add\"><i class=\"fa fa-plus\"></i>添加</a>");
                $('#editRecord').modal('show');

                $('#record-add').on('click', function () {
                    //获取提交数据
                    var formdata = $("form[name=editForm]").serialize();
                    // console.log($("form[name=editForm]").serialize());

                    $.ajax({
                        url: "/admin/sn/create",
                        async: false,
                        type: "post",
                        data: formdata,
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("添加成功");
                                window.location.reload();
                            } else {
                                alert("修改失败");
                            }
                        }
                    })
                })
            });

        },
        //批量删除
        /* batchDel: function () {
             //全选
             $("#selectAll").on("click", function () {
                 if ($(this).prop("checked")) {
                     $(".data-table tbody input[type='checkbox']").not(this).prop("checked", true);

                 } else {
                     $(".data-table tbody input[type='checkbox']").not(this).prop("checked", false);
                 }
             });


             //操作删除
             $('#batchDel').on('click', function () {
                 var checks = $(".data-table tbody input[type='checkbox']:checked");
                 if(checks.length == 0){
                     alert("请选择要删除的账户");return;
                 }
                 // console.log(checks.length);
                 //获取要删除的id
                 var idArr = [];
                 for(var i=0;i<checks.length;i++){
                     //checks[i].parent().next();
                     idArr.push($(checks[i]).parent().next().html());
                     // console.log($(checks[i]).parent().next().html());
                 }
                 // console.log(idArr);
                 //return;

                 //添加警告
                 $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                     "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                     "<h4 class=\"text-center\">确认要删除这些账户吗？</h4>" +
                     "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                     "</div>"
                 );
                 $('#warning-message').show();

                 //正式删除数据 传递数据给控制器
                 $('#confirm-del').on('click',function(){
                     $.ajax({
                         url:"/admin/admin_manage/deleteArr",
                         async:false,
                         type:"post",
                         data:{'id':idArr},
                         dataType:"json",
                         success:function(data){
                             if(data.code ==200){
                                 alert("批量删除成功");
                                 window.location.reload();
                             }else{
                                 alert("批量删除失败");
                             }
                         }
                     })
                 })

                 //手动关闭警告框
                 $('#warning-message .cancle').on('click', function () {
                     $('#warning-message').alert('close');
                 });

                 //警告框移除后事件
                 $('#warning-message').on('closed.bs.alert', function () {
                     $('.data-table tr').removeClass('danger'); //清除行高亮
                 });

                 //alert('批量删除');

             });
         },*/
        //搜索
        search: function () {
            JustMarvel.potting.search.searchByKeyword();
        },
        //清空搜索
        delSearch: function () {
            JustMarvel.potting.search.delSearch();
        },
        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };

    //工单管理
    JustMarvel.platform.pageWrokOrder = {
        init: function () {
            // console.log("工单管理");
            JustMarvel.platform.pageWrokOrder.menu();
            JustMarvel.platform.pageWrokOrder.dataInit();
            JustMarvel.platform.pageWrokOrder.handleRecord();
            //JustMarvel.platform.pageWrokOrder.editRecord();
            JustMarvel.platform.pageWrokOrder.delRecord();
            //JustMarvel.platform.pageWrokOrder.addRecord();
            JustMarvel.platform.pageWrokOrder.batchDel();
            JustMarvel.platform.pageWrokOrder.search();
            JustMarvel.platform.pageWrokOrder.goto();
        },
        menu: function () {

        },
        //数据初始化
        dataInit: function () {
            //$(".record-tool li a").on('click', function () {
            //    $("#edit-content").fadeToggle(300, 'easeInCubic');
            //});

        },

        //处理
        handleRecord: function () {
            $('.handleRecord').on('click', function () {
                alert("处理");

            });
        },
        //删除
        delRecord: function () {
            $('.delRecord').on('click', function () {
                $(this).parents('tr').addClass('danger');
                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除该条记录吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });
                //获取要删除的id
                var deleId = $(this).data('name');

                //确认删除
                $('#confirm-del').on('click', function () {
                    // console.log(deleId);
                    $.ajax({
                        url: "/admin/work_order/delete?id=" + deleId,
                        async: false,
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("删除成功");
                                window.location.reload();
                            } else {
                                alert("删除失败");
                            }
                        }
                    })
                    $('#warning-message').alert('close');

                });
            });
        },

        //批量删除
        batchDel: function () {
            //全选
            $("#selectAll").on("click", function () {
                if ($(this).prop("checked")) {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", true);

                } else {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", false);
                }
            });


            //操作删除
            $('#batchDel').on('click', function () {
                var checks = $(".data-table tbody input[type='checkbox']:checked");
                if (checks.length == 0) {
                    alert("请选择要删除的账户");
                    return;
                }
                // console.log(checks.length);
                //获取要删除的id
                var idArr = [];
                for (var i = 0; i < checks.length; i++) {
                    //checks[i].parent().next();
                    idArr.push($(checks[i]).parent().next().html());
                    // console.log($(checks[i]).parent().next().html());
                }
                // console.log(idArr);
                //return;

                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除这些账户吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //正式删除数据 传递数据给控制器
                $('#confirm-del').on('click', function () {
                    $.ajax({
                        url: "/admin/work_order/deleteArr",
                        async: false,
                        type: "post",
                        data: {
                            'id': idArr
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("批量删除成功");
                                window.location.reload();
                            } else {
                                alert("批量删除失败");
                            }
                        }
                    })
                })

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });

                //alert('批量删除');

            });
        },
        //搜索
        search: function () {
            JustMarvel.potting.search.searchByKeyword();
        },
        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };

    //系统设置
    JustMarvel.platform.pageSystem = {
        init: function () {
            // console.log("系统设置");
            JustMarvel.platform.pageSystem.menu();
            JustMarvel.platform.pageSystem.view();
        },
        menu: function () {

        },
        view: function () {
            $(".record-tool li a").on('click', function () {
                $("#edit-content").fadeToggle(300, 'easeInCubic');
            });

        },
    };

    //管理员设置
    JustMarvel.platform.pageAdmin = {
        init: function () {
            // console.log("管理员设置");
            JustMarvel.platform.pageAdmin.menu();
            JustMarvel.platform.pageAdmin.dataInit();
            JustMarvel.platform.pageAdmin.viewRecord();
            JustMarvel.platform.pageAdmin.editRecord();
            JustMarvel.platform.pageAdmin.delRecord();
            JustMarvel.platform.pageAdmin.addRecord();
            //JustMarvel.platform.pageAdmin.addJob();
            //JustMarvel.platform.pageAdmin.addGroup();
            JustMarvel.platform.pageAdmin.batchDel();
            JustMarvel.platform.pageAdmin.search();
            JustMarvel.platform.pageAdmin.delSearch();
            JustMarvel.platform.pageAdmin.goto();
        },
        menu: function () {

        },
        //数据初始化
        dataInit: function () {
            //$(".record-tool li a").on('click', function () {
            //    $("#edit-content").fadeToggle(300, 'easeInCubic');
            //});

        },
        //查看
        viewRecord: function () {
            $('.viewRecord').on('click', function () {
                var viewId = $(this).data('name');
                // console.log(viewId);
                // $('#nopass').hide();
                // $('#nopass input').attr('disabled', 'disabled');
                //往后台传送数据
                $.ajax({
                    url: "/adminmanage",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            // console.log(data);
                            // console.log($("#username"));
                            // console.log(data.view.admin_group_id);
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#adusername").val(data.view.username);
                            $("#password").val(data.view.password);
                            $("#admin_group_id").val(data.view.admin_group_id);
                            $("#mobile").val(data.view.mobile);
                            $("#updated_at").val(data.view.updated_at);


                            $('#viewRecord').find('input,select').attr("disabled", true); //disabled要在数据获取后添加，先写数据获取的方法，数据填充后VIEW操作，给所有INPUT，SELECT添加disabled
                            $('#viewRecord').modal('show'); //显示模态框
                            $(this).parents('tr').addClass('info'); //高亮选中行

                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });

            $('#viewRecord').on('hidden.bs.modal', function (e) {
                //这里要执行清除数据
                $('#viewRecord').find('input,select').attr("disabled", false); //要清除表单数据
                //添加的按钮需要清除
                $('#record-submit').remove();
                $('#record-add').remove();

                $('.data-table tr').removeClass('info'); //清除行高亮
            })
        },
        //编辑
        editRecord: function () {
            $('.editRecord').on('click', function () {
                // $('#nocreate').hide();
                // $('#nocreate input').attr('disabled', 'disabled');
                var viewId = $(this).data('name');
                // console.log(viewId);
                //从接口查询数据
                $.ajax({
                    url: "/adminmanage",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#adusername").val(data.view.username);
                            $("#password").val(data.view.password);
                            $("#admin_group_id").val(data.view.admin_group_id);
                            $("#mobile").val(data.view.mobile);
                            //$("#created_at").val(data.view.created_at);
                            // console.log(data.view.username);
                            $(this).parents('tr').addClass('warning');
                            //这里先通过接口获取数据，获取数据后，添加编辑按钮
                            $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-submit\"><i class=\"fa fa-save\"></i>保存</a>");
                            $('#viewRecord').modal('show');

                            //添加的提交按钮，绑定提交事件
                            $('#record-submit').on('click', function () {
                                // console.log($("#accountname").val());
                                var formdata = $("form[name=editForm]").serialize();
                                // console.log($("form[name=editForm]").serialize());

                                $.ajax({
                                    url: "/admin/admin_manage/edit?id=" + viewId,
                                    async: false,
                                    type: "post",
                                    data: formdata,
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.code == 200) {
                                            alert("修改成功");
                                            window.location.reload();
                                        } else {
                                            alert("修改失败");
                                        }
                                    }
                                })

                            });
                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });
            //模态框隐藏后事件
            $('#viewRecord').on('hidden.bs.modal', function () {
                $('#record-submit').remove();
                $('#record-add').remove();
                //$('#nocreate').show();
                //$('#nocreate input').removeAttr('disabled','disabled');
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });

        },
        //删除
        delRecord: function () {
            $('.delRecord').on('click', function () {
                $(this).parents('tr').addClass('danger');
                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除该条记录吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });
                //获取要删除的id
                var deleId = $(this).data('name');

                //确认删除
                $('#confirm-del').on('click', function () {
                    // console.log(deleId);
                    $.ajax({
                        url: "/admin/admin_manage/delete?id=" + deleId,
                        async: false,
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("删除成功");
                                window.location.reload();
                            } else {
                                alert("删除失败");
                            }
                        }
                    })
                    $('#warning-message').alert('close');

                });
            });
        },
        //增加
        addRecord: function () {
            $('#addRecord').on('click', function () {
                // $(":input","form[name=editForm]").not(":button",":reset","hidden","submit").val("").removeAttr("checked").removeAttr("selected");
                $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-add\"><i class=\"fa fa-plus\"></i>添加</a>");
                //$('#nocreate').hide();
                // $('#nocreate input').attr('disabled', 'disabled');
                $('#viewRecord').modal('show');

                $('#record-add').on('click', function () {
                    //获取提交数据
                    var formdata = $("form[name=editForm]").serialize();
                    // console.log($("form[name=editForm]").serialize());

                    $.ajax({
                        url: "/admin/admin_manage/create",
                        async: false,
                        type: "post",
                        data: formdata,
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("添加成功");
                                window.location.reload();
                            } else {
                                alert("修改失败");
                            }
                        }
                    })
                })
            });

        },
        //批量删除
        batchDel: function () {
            //全选
            $("#selectAll").on("click", function () {
                if ($(this).prop("checked")) {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", true);

                } else {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", false);
                }
            });


            //操作删除
            $('#batchDel').on('click', function () {
                var checks = $(".data-table tbody input[type='checkbox']:checked");
                if (checks.length == 0) {
                    alert("请选择要删除的账户");
                    return;
                }
                // console.log(checks.length);
                //获取要删除的id
                var idArr = [];
                for (var i = 0; i < checks.length; i++) {
                    //checks[i].parent().next();
                    idArr.push($(checks[i]).parent().next().html());
                    // console.log($(checks[i]).parent().next().html());
                }
                // console.log(idArr);
                //return;

                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除这些账户吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //正式删除数据 传递数据给控制器
                $('#confirm-del').on('click', function () {
                    $.ajax({
                        url: "/admin/admin_manage/deleteArr",
                        async: false,
                        type: "post",
                        data: {
                            'id': idArr
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("批量删除成功");
                                window.location.reload();
                            } else {
                                alert("批量删除失败");
                            }
                        }
                    })
                })

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });

                //alert('批量删除');

            });
        },
        //搜索
        search: function () {
            JustMarvel.potting.search.searchByKeyword();
        },
        //清空搜索
        delSearch: function () {
            JustMarvel.potting.search.delSearch();
        },
        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };

    //角色设置
    JustMarvel.platform.pageRules = {
        init: function () {
            // console.log("管理员角色设置");
            JustMarvel.platform.pageRules.menu();
            JustMarvel.platform.pageRules.dataInit();
            JustMarvel.platform.pageRules.viewRecord();
            JustMarvel.platform.pageRules.editRecord();
            JustMarvel.platform.pageRules.delRecord();
            JustMarvel.platform.pageRules.addRecord();
            JustMarvel.platform.pageRules.addJob();
            JustMarvel.platform.pageRules.batchDel();
            JustMarvel.platform.pageRules.search();
            JustMarvel.platform.pageRules.delSearch();
            JustMarvel.platform.pageRules.goto();
        },
        menu: function () {

        },
        //数据初始化
        dataInit: function () {
            //$(".record-tool li a").on('click', function () {
            //    $("#edit-content").fadeToggle(300, 'easeInCubic');
            //});
        },
        //查看
        viewRecord: function () {
            $('.viewRecord').on('click', function () {
                var viewId = $(this).data('name');
                // console.log(viewId);
                //往后台传送数据
                $.ajax({
                    url: "/admingroup",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            console.log(data);
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#gillustration").html(data.view.gillustration);
                            $("#name").val(data.view.name);

                            if (data.view.menu_id.length == 0) {
                                return;
                            }
                            for (var i = 0; i < data.view.menu_id.length; i++) {
                                $("input.mcheck.m" + data.view.menu_id[i]).attr("checked", "checked");
                            }


                            $('#viewRecord').find('input,select,textarea').attr("disabled", true); //disabled要在数据获取后添加，先写数据获取的方法，数据填充后VIEW操作，给所有INPUT，SELECT添加disabled
                            $('#viewRecord').modal('show'); //显示模态框
                            $(this).parents('tr').addClass('info'); //高亮选中行

                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });

            $('#viewRecord').on('hidden.bs.modal', function (e) {
                //这里要执行清除数据
                $('#viewRecord').find('input,select,textarea').attr("disabled", false); //要清除表单数据
                // $('#viewRecord .form-horizontal .mcheck').removeAttr('checked');
                //添加的按钮需要清除
                $('#record-submit').remove();
                $('#record-add').remove();

                $('.data-table tr').removeClass('info'); //清除行高亮
            })
        },
        //编辑
        editRecord: function () {
            $('.editRecord').on('click', function () {
                $('#nocreate').hide();
                $('#nocreate input').attr('disabled', 'disabled');
                var viewId = $(this).data('name');
                // console.log(viewId);
                //从接口查询数据
                $.ajax({
                    url: "/admingroup",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#name").val(data.view.name);
                            if (data.view.menu_id.length == 0) {
                                return;
                            }
                            for (var i = 0; i < data.view.menu_id.length; i++) {
                                $("input." +
                                    "mcheck.m" + data.view.menu_id[i]).attr("checked", "checked");
                            }

                            $(this).parents('tr').addClass('warning');
                            //这里先通过接口获取数据，获取数据后，添加编辑按钮
                            $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-submit\"><i class=\"fa fa-save\"></i>保存</a>");
                            $('#viewRecord').modal('show');

                            //添加的提交按钮，绑定提交事件
                            $('#record-submit').on('click', function () {
                                // console.log($("#accountname").val());
                                var formdata = $("form[name=editForm]").serialize();
                                // console.log($("form[name=editForm]").serialize());

                                $.ajax({
                                    url: "/admin/admin_group/edit?id=" + viewId,
                                    async: false,
                                    type: "post",
                                    data: formdata,
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.code == 200) {
                                            alert("修改成功");
                                            window.location.reload();
                                        } else {
                                            alert("修改失败");
                                        }
                                    }
                                })
                            });
                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });
            //模态框隐藏后事件
            $('#viewRecord').on('hidden.bs.modal', function () {
                $('#viewRecord').find('input[type=text],select,textarea').attr("disabled", false).val(""); //要清除表单数据
                // $('#viewRecord .form-horizontal .mcheck').removeAttr('checked');
                $('#record-submit').remove();
                $('#record-add').remove();
                //$('#nocreate').show();
                //$('#nocreate input').removeAttr('disabled','disabled');
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });

        },
        //增加
        addRecord: function () {
            $('#addRecord').on('click', function () {
                $('#viewRecord .form-horizontal .mcheck').removeAttr('checked');
                //$(":input","form[name=editForm]").not(":button",":reset","hidden","submit").val("").removeAttr("checked").removeAttr("selected");
                $('#viewRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-add\"><i class=\"fa fa-plus\"></i>添加</a>");
                $('#nocreate').hide();
                $('#nocreate input').attr('disabled', 'disabled');
                $('#viewRecord').modal('show');

                $('#record-add').on('click', function () {
                    //获取提交数据
                    var formdata = $("form[name=editForm]").serialize();
                    console.log($("form[name=editForm]").serialize());


                    $.ajax({
                        url: "/admin/admin_group/create",
                        async: false,
                        type: "post",
                        data: formdata,
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("添加成功");
                                window.location.reload();
                            } else {
                                alert("修改失败");
                            }
                        }
                    })
                })
            });

        },
        //增加权限
        addJob: function () {
            $('#addJob').on('click', function () {
                $('#addJobR .modal-footer').append("<a class=\"btn btn-success\" id=\"record-add\"><i class=\"fa fa-plus\"></i>添加</a>");
                $('#nocreate').hide();
                $('#nocreate input').attr('disabled', 'disabled');
                $('#addJobR').modal('show');

                $('#record-add').on('click', function () {
                    //获取提交数据
                    var formdata = $("form[name=edit2Form]").serialize();
                    // console.log($("form[name=edit2Form]").serialize());
                    $.ajax({
                        url: "/admin/admin_group/createJob",
                        async: false,
                        type: "post",
                        data: formdata,
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("添加成功");
                                window.location.reload();
                            } else {
                                alert("添加失败");
                            }
                        }
                    })
                })
            });

        },
        //删除
        delRecord: function () {
            $('.delRecord').on('click', function () {
                $(this).parents('tr').addClass('danger');
                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除该条记录吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });
                //获取要删除的id
                var deleId = $(this).data('name');

                //确认删除
                $('#confirm-del').on('click', function () {
                    // console.log(deleId);
                    $.ajax({
                        url: "/admin/admin_group/delete?id=" + deleId,
                        async: false,
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("删除成功");
                                window.location.reload();
                            } else {
                                alert("删除失败");
                            }
                        }
                    })
                    $('#warning-message').alert('close');

                });
            });
        },
        //批量删除
        batchDel: function () {
            //全选
            $("#selectAll").on("click", function () {
                if ($(this).prop("checked")) {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", true);

                } else {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", false);
                }
            });


            //操作删除
            $('#batchDel').on('click', function () {
                var checks = $(".data-table tbody input[type='checkbox']:checked");
                if (checks.length == 0) {
                    alert("请选择要删除的账户");
                    return;
                }
                // console.log(checks.length);
                //获取要删除的id
                var idArr = [];
                for (var i = 0; i < checks.length; i++) {
                    //checks[i].parent().next();
                    idArr.push($(checks[i]).parent().next().html());
                    // console.log($(checks[i]).parent().next().html());
                }
                // console.log(idArr);
                //return;

                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除这些账户吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //正式删除数据 传递数据给控制器
                $('#confirm-del').on('click', function () {
                    $.ajax({
                        url: "/admin/admin_group/deleteArr",
                        async: false,
                        type: "post",
                        data: {
                            'id': idArr
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("批量删除成功");
                                window.location.reload();
                            } else {
                                alert("批量删除失败");
                            }
                        }
                    })
                })

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });

                //alert('批量删除');

            });
        },
        //搜索
        search: function () {
            JustMarvel.potting.search.searchByKeyword();
        },
        //清空搜索
        delSearch: function () {
            JustMarvel.potting.search.delSearch();
        },
        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };

    //文档管理
    JustMarvel.platform.pageDocManage = {
        init: function () {
            // console.log("文档管理");
            JustMarvel.platform.pageDocManage.menu();
            JustMarvel.platform.pageDocManage.dataInit();
            JustMarvel.platform.pageDocManage.viewRecord();
            JustMarvel.platform.pageDocManage.editRecord();
            JustMarvel.platform.pageDocManage.delRecord();
            JustMarvel.platform.pageDocManage.addRecord();
            JustMarvel.platform.pageDocManage.batchDel();
            JustMarvel.platform.pageDocManage.goto();
        },
        menu: function () {

        },
        //数据初始化
        dataInit: function () {

        },

        //查看
        viewRecord: function () {
            $('.viewRecord').on('click', function () {
                var viewId = $(this).data('name');
                var typeId = $(this).data('type');
                // console.log(viewId);
                //往后台传送数据
                $.ajax({
                    url: "/docmanage",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId,
                        'typeId': typeId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            // console.log(data);
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#name").val(data.view.name);
                            $("#remark").val(data.view.remark);
                            //$("#textcontent").html(data.view.text);
                            //ue.setContent(data.view.text);
                            // console.log($("#ueditor").val(data.view.editor));
                            if (typeId == 1) {
                                ue.setContent(data.view.text);
                                $(".type_id.t1").attr("checked", 'checked');
                                $("#helpDoc").css('display', 'block');
                                $("#agreement").css('display', 'none');
                                $("#doc_about").css('display', 'none');

                            } else if (typeId == 0) {
                                $("#textcontent").html(data.view.text);
                                $(".type_id.t0").attr("checked", 'checked');
                                $("#agreement").css('display', 'block');
                                $("#helpDoc").css('display', 'none');
                                $("#doc_about").css('display', 'none');

                            } else if (typeId == 2) {
                                ue2.setContent(data.view.text);
                                $(".type_id.t2").attr("checked", 'checked');
                                $("#doc_about").css('display', 'block');
                                $("#agreement").css('display', 'none');
                                $("#helpDoc").css('display', 'none');

                            }


                            $('#docmanage').find('input,select,textarea').attr("disabled", true); //disabled要在数据获取后添加，先写数据获取的方法，数据填充后VIEW操作，给所有INPUT，SELECT添加disabled
                            $('#docmanage').modal('show'); //显示模态框
                            $(this).parents('tr').addClass('info'); //高亮选中行

                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });

            $('#docmanage').on('hidden.bs.modal', function (e) {
                //这里要执行清除数据
                $('#docmanage').find('input,select').attr("disabled", false); //要清除表单数据
                //添加的按钮需要清除
                $('#record-submit').remove();
                $('#record-add').remove();

                $('.data-table tr').removeClass('info'); //清除行高亮
            })
        },

        //编辑
        editRecord: function () {
            $('.editRecord').on('click', function () {
                var viewId = $(this).data('name');
                var typeId = $(this).data('type');
                // console.log(viewId);
                //从接口查询数据
                $.ajax({
                    url: "/docmanage",
                    async: false,
                    type: "post",
                    data: {
                        'viewId': viewId,
                        'typeId': typeId
                    },
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            //console.log(data.view.text);
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            $("#recordId").html(data.view.id);
                            $("#name").val(data.view.name);
                            $("#remark").val(data.view.remark);

                            // console.log($("#ueditor").val(data.view.editor));
                            if (typeId == 1) {
                                $("input.type_id.t0").removeAttr("checked");
                                $("input.type_id.t2").removeAttr("checked");
                                $("input.type_id.t1").prop("checked", 'checked');
                                $("#helpDoc").css('display', 'block');
                                $("#doc_about").css('display', 'none');
                                $("#agreement").css('display', 'none');
                                ue.setContent(data.view.text);
                            } else if (typeId == 0) {
                                $("input.type_id.t1").removeAttr("checked");
                                $("input.type_id.t2").removeAttr("checked");
                                $("input.type_id.t0").prop("checked", 'checked');
                                $("#agreement").css('display', 'block');
                                $("#doc_about").css('display', 'none');
                                $("#helpDoc").css('display', 'none');
                                $("#textcontent").val(data.view.text);
                            } else if (typeId == 2) {
                                $("input.type_id.t1").removeAttr("checked");
                                $("input.type_id.t0").removeAttr("checked");
                                $("input.type_id.t2").prop("checked", 'checked');
                                $("#doc_about").css('display', 'block');
                                $("#agreement").css('display', 'none');
                                $("#helpDoc").css('display', 'none');
                                ue2.setContent(data.view.text);
                            }
                            //文档类型不可修改
                            $('#docmanage .type_id').attr("disabled", true);
                            $('#textcontent').attr("disabled", false);
                            //$('#textabout').attr("disabled", false);
                            $(this).parents('tr').addClass('warning');
                            //这里先通过接口获取数据，获取数据后，添加编辑按钮
                            $('#docmanage .modal-footer').append("<a class=\"btn btn-success\" id=\"record-submit\"><i class=\"fa fa-save\"></i>保存</a>");
                            $('#docmanage').modal('show');

                            //添加的提交按钮，绑定提交事件
                            $('#record-submit').on('click', function () {
                                var formdata = $("form[name=editForm]").serialize();

                                $.ajax({
                                    url: "/admin/doc_manage/edit?id=" + viewId,
                                    async: false,
                                    type: "post",
                                    data: formdata + "&type_id=" + $("input[name=type_id]:checked").val(),
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.code == 200) {
                                            alert("修改成功");
                                            window.location.reload();
                                        } else {
                                            alert("修改失败");
                                        }
                                    }
                                })

                            });

                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("提交数据失败");
                        }
                    }
                });
            });
            //模态框隐藏后事件
            $('#docmanage').on('hidden.bs.modal', function () {
                $('#docmanage').find('input[type=text],select,textarea').attr("disabled", false).val(""); //要清除表单数据
                $('#docmanage .form-horizontal .type_id').removeAttr('checked');
                //$(":input","form[name=editForm]").not(":button",":reset","hidden","submit").val("").removeAttr("checked").removeAttr("selected");
                $('#record-submit').remove();
                $('#record-add').remove();
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });

        },

        //增加
        addRecord: function () {
            $('#addRecord').on('click', function () {
                $('#agreement').hide();
                $('#helpDoc').hide();
                $('#doc_about').hide();
                ue.setContent("初始化编辑内容");
                ue2.setContent("初始化编辑内容");
                $('#docmanage .modal-footer').append("<a class=\"btn btn-success\" id=\"record-add\"><i class=\"fa fa-plus\"></i>添加</a>");
                $('#nocreate').hide();
                $('#nocreate input').attr('disabled', 'disabled');
                $('#docmanage').modal('show');

                $('#docmanage .form-horizontal .type_id').on('click', function () {
                    var type = $("input[name=type_id]:checked").val();
                    console.log(type);
                    if (type == 1) {
                        $("#helpDoc").css('display', 'block');
                        $("#doc_about").css('display', 'none');
                        $("#agreement").css('display', 'none');

                    } else if (type == 0) {
                        $("#agreement").css('display', 'block');
                        $("#doc_about").css('display', 'none');
                        $("#helpDoc").css('display', 'none');
                    } else if (type == 2) {
                        $("#doc_about").css('display', 'block');
                        $("#agreement").css('display', 'none');
                        $("#helpDoc").css('display', 'none');
                    }
                });

                $('#record-add').on('click', function () {
                    //获取提交数据
                    var formdata = $("form[name=editForm]").serialize();                    
//console.log(formdata);return;
                    $.ajax({
                        url: "/admin/doc_manage/create",
                        async: false,
                        type: "post",
                        data: formdata,
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("添加成功");
                                window.location.reload();
                            } else {
                                alert("修改失败");
                            }
                        }
                    })
                })
            });

        },

        //删除
        delRecord: function () {
            $('.delRecord').on('click', function () {
                $(this).parents('tr').addClass('danger');
                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除该条记录吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });
                //获取要删除的id
                var deleId = $(this).data('name');

                //确认删除
                $('#confirm-del').on('click', function () {
                    // console.log(deleId);
                    $.ajax({
                        url: "/admin/doc_manage/delete?id=" + deleId,
                        async: false,
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("删除成功");
                                window.location.reload();
                            } else {
                                alert("删除失败");
                            }
                        }
                    })
                    $('#warning-message').alert('close');

                });
            });
        },

        //批量删除
        batchDel: function () {
            //全选
            $("#selectAll").on("click", function () {
                if ($(this).prop("checked")) {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", true);

                } else {
                    $(".data-table tbody input[type='checkbox']").not(this).prop("checked", false);
                }
            });


            //操作删除
            $('#batchDel').on('click', function () {
                var checks = $(".data-table tbody input[type='checkbox']:checked");
                if (checks.length == 0) {
                    alert("请选择要删除的账户");
                    return;
                }
                // console.log(checks.length);
                //获取要删除的id
                var idArr = [];
                for (var i = 0; i < checks.length; i++) {
                    //checks[i].parent().next();
                    idArr.push($(checks[i]).parent().next().html());
                    // console.log($(checks[i]).parent().next().html());
                }
                // console.log(idArr);
                //return;

                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除这些账户吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //正式删除数据 传递数据给控制器
                $('#confirm-del').on('click', function () {
                    $.ajax({
                        url: "/admin/doc_manage/deleteArr",
                        async: false,
                        type: "post",
                        data: {
                            'id': idArr
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("批量删除成功");
                                window.location.reload();
                            } else {
                                alert("批量删除失败");
                            }
                        }
                    })
                })

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });

                //alert('批量删除');

            });
        },

        //搜索
        // search: function () {
        //     JustMarvel.potting.search.searchByKeyword();
        // },

        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };

    //图片管理
    JustMarvel.platform.pageImageLibrary = {
        init: function () {
            // console.log("图片管理");
            JustMarvel.platform.pageImageLibrary.menu();
            JustMarvel.platform.pageImageLibrary.dataInit();
            //JustMarvel.platform.pageImageLibrary.videoPlay();
            JustMarvel.platform.pageImageLibrary.downLoad();
            JustMarvel.platform.pageImageLibrary.delRecord();
            JustMarvel.platform.pageImageLibrary.search();
            JustMarvel.platform.pageImageLibrary.goto();
        },
        menu: function () {

        },
        dataInit: function () {
            $(".record-tool li a").on('click', function () {
                $("#edit-content").fadeToggle(300, 'easeInCubic');
            });

        },

        /* videoPlay: function () {
             $('.video-play').on('click', function () {
                 var playname = $(this).data('name');
                 // console.log(playname);
                 var playurl = $(this).data('videourl');
                 $('#userName').html(playname);
                 $('#custom-video').empty().append("<source src="+playurl+" type=\"video/mp4\" />");
                 $('#modal-video').modal('show');

             });
             $('#modal-video').on('hide.bs.modal', function () {
                 $('#custom-video').get(0).pause();
                 $('#custom-video').load();
                 $('#custom-video').empty();

             });
         },*/

        //下载视频
        downLoad: function () {
            /* $('.downLoad').on('click', function () {
                 var url = $(this).data('url');
                 // console.log(url);
                 //window.open("http://www.icm.com/static/upload/20190228/0.mp4");
                 // $.ajax({
                 //     url:"/admin/video_library/download?url="+url,
                 //     async:false,
                 //     type:"get",
                 //     dataType:"json",
                 //     success:function(data){
                 //         // console.log(data);
                 //         if(data.code !=200){
                 //             alert("下载失败");
                 //             //window.location.reload();
                 //         }
                 //     }
                 // })
             });*/
        },

        //删除
        delRecord: function () {
            $('.delRecord').on('click', function () {
                $(this).parents('tr').addClass('danger');
                //添加警告
                $body.append("<div id=\"warning-message\" class=\"alert alert-danger alert-dismissible fade in\" role=\"alert\">" +
                    "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>" +
                    "<h4 class=\"text-center\">确认要删除该条记录吗？</h4>" +
                    "<p class=\"text-center\"><a id=\"confirm-del\" class=\"btn btn-danger\">确认删除</a><a class=\"btn btn-default cancle\" >取消</a></p>" +
                    "</div>"
                );
                $('#warning-message').show();

                //手动关闭警告框
                $('#warning-message .cancle').on('click', function () {
                    $('#warning-message').alert('close');
                });

                //警告框移除后事件
                $('#warning-message').on('closed.bs.alert', function () {
                    $('.data-table tr').removeClass('danger'); //清除行高亮
                });
                //获取要删除的id
                var deleId = $(this).data('name');

                //确认删除
                $('#confirm-del').on('click', function () {
                    // console.log(deleId);
                    $.ajax({
                        url: "/admin/image_library/delete?id=" + deleId,
                        async: false,
                        type: "get",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("删除成功");
                                window.location.reload();
                            } else {
                                alert("删除失败");
                            }
                        }
                    })
                    $('#warning-message').alert('close');

                });
            });
        },

        //搜索
        // search: function () {
        //     JustMarvel.potting.search.searchByKeyword();
        // },

        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        }
    };


    //意见反馈
    JustMarvel.platform.pageFeedback = {
        init: function () {
            // console.log("意见反馈");
            JustMarvel.platform.pageFeedback.menu();
            JustMarvel.platform.pageFeedback.dataInit();
            JustMarvel.platform.pageFeedback.replyRecord();
            JustMarvel.platform.pageFeedback.viewRecord();
            JustMarvel.platform.pageFeedback.search();
            JustMarvel.platform.pageFeedback.delSearch();
            JustMarvel.platform.pageFeedback.goto();
        },
        menu: function () {

        },

        //数据初始化
        dataInit: function () {
            //$(".record-tool li a").on('click', function () {
            //    $("#edit-content").fadeToggle(300, 'easeInCubic');
            //});

        },
        //查询数据
        viewRecord: function () {
            $('.viewRecord').on('click', function () {
                var nameId = $(this).data('name');
                console.log(nameId);
                //往后台传送数据
                $.ajax({
                    url: "/admin/feedback/view?&user_id=" + nameId,
                    async: false,
                    type: "get",
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            console.log(data.data.list);
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            var str_td = "";
                            for (var i = 0; i < data.data.list.length; i++) {
                                if (data.data.list[i]['admin_id'] == 0) {
                                    str_td += "<tr class=\"active\" ><td>" + data.data.list[i]['content'] + "</td></tr>";
                                } else {
                                    str_td += "<tr class=\"success\"><td>" + data.data.list[i]['content'] + "</td></tr>";
                                }

                            }
                            if (str_td == "") {
                                str_td = "<tr><td>暂无数据</td><td>暂无数据</td></tr>";
                            }
                            $("#viewRecord tbody").html(str_td);
                            $(this).parents('tr').addClass('info'); //高亮选中行

                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("查询失败");
                        }
                    }
                });
            });
        },
        //回复
        replyRecord: function () {
            $(document).on('click', '.replyRecord', function () {
                var id = $(this).data('id');
                var name = $(this).data('name');
                $("#recordId").html(id);
                $('#replyRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-submit\"><i class=\"fa fa-save\"></i>保存</a>");
                $('#replyRecord').modal('show');

                $('#record-submit').on('click', function () {
                    //获取提交数据
                    var content = $("#content").val();
                    // console.log($("form[name=editForm]").serialize());

                    $.ajax({
                        url: "/admin/feedback/reply?id=" + id + "&user_id=" + name,
                        async: false,
                        type: "post",
                        data: {
                            'content': content
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("回复成功");
                                window.location.reload();
                            } else {
                                alert("回复失败");
                            }
                        }
                    })
                })
            });
            //模态框隐藏后事件
            $('#replyRecord').on('hidden.bs.modal', function () {
                $('#record-submit').remove();
                $('#record-add').remove();
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });

        },
        //搜索
        search: function () {
            JustMarvel.potting.search.searchByKeyword();
        },
        //清空搜索
        delSearch: function () {
            JustMarvel.potting.search.delSearch();
        },
        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        },
    };

    //故障报修
    JustMarvel.platform.pageFaultrepair = {
        init: function () {
            // console.log("意见反馈");
            JustMarvel.platform.pageFaultrepair.menu();
            JustMarvel.platform.pageFaultrepair.dataInit();
            JustMarvel.platform.pageFaultrepair.replyRecord();
            JustMarvel.platform.pageFaultrepair.viewRecord();
            JustMarvel.platform.pageFaultrepair.search();
            JustMarvel.platform.pageFaultrepair.delSearch();
            JustMarvel.platform.pageFaultrepair.goto();
        },
        menu: function () {

        },

        //数据初始化
        dataInit: function () {
            //$(".record-tool li a").on('click', function () {
            //    $("#edit-content").fadeToggle(300, 'easeInCubic');
            //});

        },
        //查询数据
        viewRecord: function () {
            $('.viewRecord').on('click', function () {
                var nameId = $(this).data('name');
                console.log(nameId);
                //往后台传送数据
                $.ajax({
                    url: "/admin/fault_repair/view?&user_id=" + nameId,
                    async: false,
                    type: "get",
                    dataType: "json",
                    success: function (data) {
                        //flag = data.checkResult;
                        if (data.code == 200) {
                            //绑定后台传送来的数据
                            console.log(data.data.list);
                            //document.getElementById("recordId").innerHTML=data.view[0].id;
                            var str_td = "";
                            for (var i = 0; i < data.data.list.length; i++) {
                                if (data.data.list[i]['admin_id'] == 0) {
                                    str_td += "<tr class=\"active\" ><td>" + data.data.list[i]['content'] + "</td></tr>";
                                } else {
                                    str_td += "<tr class=\"success\"><td>" + data.data.list[i]['content'] + "</td></tr>";
                                }

                            }
                            if (str_td == "") {
                                str_td = "<tr><td>暂无数据</td><td>暂无数据</td></tr>";
                            }
                            $("#viewRecord tbody").html(str_td);
                            $(this).parents('tr').addClass('info'); //高亮选中行

                            // console.log(data) ;
                            // console.log("数据提交成功");
                        } else {
                            alert("查询失败");
                        }
                    }
                });
            });
        },
        //回复
        replyRecord: function () {
            $(document).on('click', '.replyRecord', function () {
                var id = $(this).data('id');
                var name = $(this).data('name');
                $("#recordId").html(id);
                $('#replyRecord .modal-footer').append("<a class=\"btn btn-success\" id=\"record-submit\"><i class=\"fa fa-save\"></i>保存</a>");
                $('#replyRecord').modal('show');

                $('#record-submit').on('click', function () {
                    //获取提交数据
                    var content = $("#content").val();
                    // console.log($("form[name=editForm]").serialize());

                    $.ajax({
                        url: "/admin/fault_repair/reply?id=" + id + "&user_id=" + name,
                        async: false,
                        type: "post",
                        data: {
                            'content': content
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {
                                alert("回复成功");
                                window.location.reload();
                            } else {
                                alert("回复失败");
                            }
                        }
                    })
                })
            });
            //模态框隐藏后事件
            $('#replyRecord').on('hidden.bs.modal', function () {
                $('#record-submit').remove();
                $('#record-add').remove();
                $('.data-table tr').removeClass('warning'); //清除行高亮
            });

        },
        //搜索
        search: function () {
            JustMarvel.potting.search.searchByKeyword();
        },
        //清空搜索
        delSearch: function () {
            JustMarvel.potting.search.delSearch();
        },
        //前往页面
        goto: function () {
            JustMarvel.potting.pagination.goto();
        },
    };

    //DOM加载完成
    JustMarvel.documentOnReady = {
        init: function () {}
    };

    //文档加载完成
    JustMarvel.documentOnLoad = {
        init: function () {
            JustMarvel.initialize.init();
        }
    };
    JustMarvel.documentOnResize = {
        init: function () {}
    };

    //全局参数定义
    var currenttime = function () {
        var currenttime = new Date().toLocaleTimeString().replace(/^\D*/, '');
        return currenttime;
    };

    //全局页面DOM定义
    var $window = $(window),
        $body = $('body'),
        $wrapper = $("#wrapper");

    var $pageIndex = $(".page-index"),
        $pageAccount = $(".page-account"),
        $pageAccountGroup = $(".page-accountGroup"),
        $pageAgent = $(".page-agent"),
        $pageAgentGroup = $(".page-agentGroup"),
        $pageAgentLevel = $(".page-agentLevel"),
        $pageAgentReport = $('.page-agentReport'),
        $pageDevice = $('.page-device'),
        $pageDeviceGroup = $('.page-deviceGroup'),
        $page4G = $(".page-4g"),
        $pageVideoLibrary = $('.page-videoLibrary'),
        $pageCarData = $('.page-carData'),
        $pageCarEvent = $('.page-carEvent'),
        $pageCarManage = $('.page-carManage'),
        $pageTask = $('.page-task'),
        $pageReceipt = $('.page-receipt'),
        $pageSN = $(".page-sn"),
        $pageWrokOrder = $(".page-workOrder"),
        $pageSystem = $('.page-system'),
        $pageAdmin = $(".page-admin"),
        $pageRules = $(".page-rules"),
        $pageDocManage = $(".page-docManage"),
        $pageImageLibrary = $(".page-imageLibrary"),
        $pageFeedback = $(".page-feedback");
    $pageFaultrepair = $(".page-faultrepair");

    $(document).ready(JustMarvel.documentOnReady.init);
    $window.load(JustMarvel.documentOnLoad.init);
    $window.resize(function () {
        JustMarvel.platform.frame();
    });
})(jQuery);